├── Accolite ├── Binary Tree into its Mirror Tree.cpp ├── Implement a queue using two stacks.cpp ├── Left view of a binary tree.cpp ├── divisible by 13 and 7.cpp └── find target pair in array.cpp ├── All Algorithms ├── 01_0-1_kanpshak.cpp ├── Algebraic algorithms │ ├── BinaryExponentiation.cpp │ ├── ModularExponentiation.cpp │ └── strassen_matrix.c ├── Boyer_Moore_Majority_Voting_Algorithm.cpp ├── Brian Kernighan’s algorithm │ └── Brian_Kernighan’s_algorithm.cpp ├── Bubble_sort.cpp ├── Dynamic Programming │ └── LIS │ │ ├── Best Time to Buy and Sell Stock with K Transactions.cpp │ │ ├── Knapsack with repititions.cpp │ │ ├── LongestCommonSubSeq.cpp │ │ ├── LongestIncreasingSubsequence_Recursive.java │ │ └── Longest_Palindromic_Subsequence.java ├── Graph Algorithm │ ├── 2 SAT.cpp │ ├── BellmanFordAlgorithm.java │ ├── Dijkstra's Algorithm.cpp │ ├── Euler Tour Algorithm.cpp │ ├── Kahn's_algorithm.cpp │ ├── KahnsAlgorithmsCycleDetection.java │ ├── Kruskal Algorithm in Python.py │ ├── LCA.cpp │ ├── Prim's MST.cpp │ ├── SegmentTree(max-query).cpp │ ├── Topo-Sort-BFS │ ├── algo.cpp │ └── topologicalSort.cpp ├── KMP_search_algorithm.cpp ├── Kadane's Algorithm │ ├── Kadane's Algorithm DP.cpp │ ├── Kadane'sAlgorithm.cpp │ ├── Kadane'sAlgorithm.py │ ├── KadaneAlgorithm.java │ └── KadanesAlgo.c ├── Searching Algorithm │ ├── FibonacciSearch.cpp │ ├── TernarySearch.cpp │ ├── binary.py │ ├── binary_search.cpp │ ├── exponential_search.cpp │ ├── interpolation_search.cpp │ ├── linear_search.cpp │ └── rabinKarp_search.cpp ├── SortColors.java ├── Sorting Algorithm in Python │ ├── Recursive_Algorithms │ │ ├── Bubble_sort.py │ │ └── insertion_sort.py │ ├── bubbleSort.py │ ├── bucket_Sort.py │ ├── heap_Sort.py │ ├── insertion.py │ ├── mergeSort.py │ ├── quickSort.py │ ├── selectionSort.py │ └── tim_sort.py ├── Sorting Algorithm │ ├── BubbleSort.cpp │ ├── Bucket-BinSort.cpp │ ├── Cocktailsort.cpp │ ├── Count_sort │ │ ├── count_sort.cpp │ │ └── count_sort.exe │ ├── DNF_sort │ │ ├── dnf_sort.cpp │ │ └── dnf_sort.exe │ ├── Dijkstra Algorithm.py │ ├── INSERTION SORT.cpp │ ├── InsertionSort.cpp │ ├── IterativeMergeSort.cpp │ ├── Quick_sort │ │ ├── Quick_sort.cpp │ │ └── Quick_sort.exe │ ├── RadixSort.cpp │ ├── Randomized_Quicksort.c │ ├── RecursiveMergeSort.cpp │ ├── SelectionSort.cpp │ ├── Selection_Sort.py │ ├── ShellSort.cpp │ ├── bubble_sort.c │ ├── bubble_sort.cpp │ ├── comb_sort.cpp │ ├── counting_sort │ ├── heap_sort.cpp │ ├── insertion_sort.cpp │ ├── merge_sort.c.c │ ├── merge_sort.cpp │ ├── quick_sort.cpp │ ├── radix_sort.java │ ├── selection_sort.c │ ├── sorting_techniques.cpp │ ├── tim_sort.cpp │ └── wave_sort │ │ ├── wave_sort.cpp │ │ └── wave_sort.exe ├── String algorithms │ ├── Boyer Moore Algorithm.cpp │ ├── KMP.cpp │ ├── Z-algorithm.cpp │ ├── hashing.cpp │ ├── manacher's algorihm.cpp │ └── rabinKarpAlgorithm.cpp ├── insertion_sort.cpp └── strassen.cpp ├── All Data Structures ├── Arrays │ ├── 1) Reverse the Array.cpp │ ├── 10) Minimum number of jumps.cpp │ ├── 11) Find the Duplicate Number.cpp │ ├── 17) Longest consecutive subsequence.cpp │ ├── 2) Maximum and Minimum Element in an Array.cpp │ ├── 20) Rearrange array in alternating positive & negative items.cpp │ ├── 21) subarray with 0 sum.cpp │ ├── 22) Factorials of Large Number.cpp │ ├── 22. Find maximum product subarray.cpp │ ├── 26) Maximum profit by buying and selling a share at most twice.cpp │ ├── 3) Kth smallest Element.cpp │ ├── 33) Minimum swaps and K together.cpp │ ├── 4) Sort an array of 0s,1s and 2s.cpp │ ├── 5) Move All Negative Elements To One Side of The Array.cpp │ ├── 7) Cyclically rotate an array by one.cpp │ ├── 8) Kadane's Algorithm.cpp │ ├── 9)Minimize the heights.cpp │ ├── A chess game.cpp │ ├── Cheapest Path CodeChef.cpp │ ├── Largest and Smallest Element of a Matrix.cpp │ ├── Number of common factor.cpp │ ├── Product of array.c │ ├── Rainwater_trap.cpp │ ├── Rearrange an array with O(1) extra space.cpp │ ├── Reverse_an_array_in_python.py │ ├── TrappingRainWater.cpp │ ├── WavePrinting.cpp │ ├── array_insertion.c │ ├── duplicate_entries_in_array.c │ ├── magical_chessboard.cpp │ ├── merging_2_arrays.c │ ├── next_permutation.cpp │ ├── peak_element.cpp │ └── union and intersection of unsorted array.cpp ├── Binary Search Tree │ ├── BinarySearchTree$Node.class │ ├── BinarySearchTree.class │ ├── BinarySearchTree.java │ ├── CreateBinarySearchTree.cpp │ └── One_way_right_threaded_BST.c ├── CircularLinkedList │ ├── circular_doubly_linked_list.c │ └── circular_singly_linked_list.c ├── Doubly_LL │ ├── doubly.cpp │ ├── palindrome │ └── palindrome.cpp ├── Dynamic_Programming │ └── Coin_change ├── GRAPHS │ ├── BFS_Explanation_Graph.cpp │ ├── BellmanfordAlgo.cpp │ ├── BreadthFirstSearch.cpp │ ├── DFS-TRAVERSAL │ ├── DepthFirstSearchUsingSTL.cpp │ ├── Detect_Cycle_in_Directed_Graph.cpp │ ├── FloydWarshall.cpp │ ├── Kruskal'sMinSpanningTree.cpp │ ├── PrimsMinSpanningTree.cpp │ ├── ShortestPathBFS.cpp │ ├── dijkstra.cpp │ ├── island_count.cpp │ ├── kosaraju's_algo.cpp │ └── rottenOranges.cpp ├── Queues │ ├── Implement Stack using Queues │ ├── ImplementCircularQueue.cpp │ ├── PriorityQueue.cpp │ ├── double-ended_queue(deque) .c │ ├── queueUsingLinkedList.cpp │ └── queues_using_array ├── Segment Tree │ ├── Lazy_Propagation.cpp │ ├── RangeSumQuery.cpp │ └── segment_tree.cpp ├── Singly_LL │ ├── 142-Linked-List-Cycle-II.cpp │ ├── Delete the middle node of a linked list.py │ ├── Rotate_A_Linked_List.cpp │ ├── check-palindrome-in-ll.cpp │ ├── linkedlist.cpp │ ├── main.cpp │ ├── menu_based_singly_linked_list.cpp │ └── merge_two_sorted_ll.cpp ├── Sorting │ ├── Bubble-sort.cpp │ ├── CountSort.cpp │ ├── Heap_Sort.cpp │ ├── Insertion_sort.cpp │ ├── Radix Sort Code in cpp │ ├── Top_K_Frequent_elements.cpp │ ├── countingSort.cpp │ ├── mergeSort.cpp │ ├── quickSort.cpp │ └── selectionsort.cpp ├── Stack │ ├── Checkpalindrome.cpp │ ├── Get_minimum_element_from_stack.cpp │ ├── Largest Rectangular Area in a Histogram │ ├── Longest_valid_Parentheses.cpp │ ├── Maximum_Rectangle_Leetcode-85.cpp │ ├── Next_Greater_Element.cpp │ ├── Smallest_number_on_left.cpp │ ├── Sort_stack_using_recursion.cpp │ ├── Stock_span_problem.cpp │ ├── The_Celebrity_Problem.cpp │ ├── Trapping_rain_water.cpp │ ├── reverseStack.cpp │ ├── stack using linked list (doubly pointer) │ ├── stack_using_queues.cpp │ ├── stockspan.cpp │ └── valid_parenthesis.cpp ├── TREE │ ├── AVL.cpp │ ├── AVLTREE.C │ ├── BST.C │ ├── BST.cpp │ ├── DeletionAVL.cpp │ ├── HEIGHT OF A BINARY TREE │ ├── Left_view_Of_Binary_Tree.cpp │ ├── Level_Order_Traversal_in_Spiral_Form.cpp │ ├── Longest_path_in_tree.cpp │ ├── Prim_Algorithm.cpp │ ├── Reverse tree path.cpp │ ├── Sparse_Table_Algorithm.cpp │ ├── SumOfTreeNodes.cpp │ ├── To check if Tree is balanced or not │ ├── To print Left View of Tree │ ├── Top_View_Of_BT.cpp │ ├── Tree.c │ ├── Tree.cpp │ ├── TreeImplementationLinkedList.java │ └── fenwickTree_countInversion.cpp └── Trie │ ├── LCPtrie.cpp │ ├── trie.cpp │ └── trie.h ├── Basic Programming ├── 1192-critical-connections-in-a-network.cpp ├── ADD_TWO_MATRIX.cpp ├── ASCII Value of char.cpp ├── All_Patterns.c ├── AlphabetTriangle ├── Alphabet_Triangle.cpp ├── Armstrong Number.cpp ├── BubbleSort.cpp ├── C Program without main.c ├── Calculate Sum of Natural Numbers.cpp ├── Checking a number is prime or not.cpp ├── Checking palindrome.cpp ├── Consonanat or Vowel.cpp ├── Copy Strings.cpp ├── Difference Between Two Time Period.cpp ├── Even or odd.cpp ├── Fahrenheit to Celsius.cpp ├── Fibonacci Series.cpp ├── Find Size of int, float, double and char in Your System.cpp ├── Greatest Among three.cpp ├── GreatestAmong3No.c ├── HCFofTwoNum.cpp ├── Hello World.cpp ├── Insertion_Sort.cpp ├── Kth smallest elements.cpp ├── Largest Element in an array.cpp ├── Leap Year or Not.cpp ├── Max index.cpp ├── Merge overlapping intervals.cpp ├── Multiplication table.cpp ├── PerfectNumber.cpp ├── Print 2-D array.cpp ├── Print hello without semicolon.cpp ├── Program to Add Two Numbers.cpp ├── Program to Display Factors of a Number.cpp ├── Program to Print Number Entered by User.cpp ├── Program to Swap Two Numbers.cpp ├── PyramidNumber.cpp ├── Remainder and Quotient.cpp ├── Remove all Characters in a String Except Alphabets.cpp ├── Roots of a Quadratic Equation.cpp ├── SwapNumbersInCyclicOrder.cpp ├── Triangle of Numbers.cpp ├── Unique_hello_world.c ├── anagram.cpp ├── convert binary number to decimal.cpp ├── counting Sort.cpp ├── duplicate_array.cpp ├── euclid_gcd.cpp ├── factorial.cpp ├── matrix.cpp ├── matrix_multiply1.cpp ├── pattern.c ├── print half pyramid.cpp ├── pyramid.cpp ├── queue.c ├── selection_sort.cpp ├── sum_of_ap.cpp └── xor_equality.cpp ├── Coding Platforms(codechef,codeforces,etc) ├── CodeChef │ ├── April Cook-Off │ │ ├── BodyBuilder.cpp │ │ ├── Chocolate Monger.cpp │ │ ├── OR of ANDs.cpp │ │ ├── Passing Marks.cpp │ │ └── Small factorials.cpp │ ├── April Long Challenge 2021 │ │ ├── Chef And Dice.cpp │ │ ├── Strong Language.cpp │ │ ├── Valid Pair.cpp │ │ ├── World Record.cpp │ │ └── Worthy Matrix.cpp │ ├── April Lunch Time │ │ ├── Array Rotation.cpp │ │ ├── Bench Press.cpp │ │ └── Chef In Heaven.cpp │ ├── August Long Challenge │ │ ├── AandBequal.cpp │ │ ├── AandBequal.exe │ │ ├── HELLOEQN.cpp │ │ ├── HELLOEQN.exe │ │ ├── MAXSUBS.cpp │ │ ├── MAXSUBS.exe │ │ ├── SALESEASON.cpp │ │ ├── SALESEASON.exe │ │ ├── TWOTRAINS.cpp │ │ └── TWOTRAINS.exe │ ├── Codechef-October-Long-Challenge-2022 │ │ ├── Building_Race.cpp │ │ ├── SingleOp1.cpp │ │ └── SingleOp2.cpp │ ├── July Cook-off │ │ ├── Chef and GCD.cpp │ │ ├── Chef_in_Infinite_plane.cpp │ │ ├── Shoe_fit.cpp │ │ └── XOR-ORED.cpp │ ├── July Long Challenge │ │ ├── Game of Piles Version 1.cpp │ │ ├── Maximum Production.cpp │ │ ├── Optimal Denomination.cpp │ │ ├── Relativity.cpp │ │ └── XxOoRr.cpp │ ├── June Long Challenge 2021 │ │ └── Bella Ciao.cpp │ ├── May Long Two 2022 │ │ └── Xor_Palindrome.cpp │ ├── October Cook off 2021 │ │ ├── AVGFLEX.cpp │ │ └── CHEFSLP.cpp │ ├── October Long Challenge 2021 │ │ ├── Digit_Removal.cpp │ │ ├── LongestANDSubarray.cpp │ │ ├── MEX-OR.cpp │ │ ├── Three Boxes.cpp │ │ └── Which Mixture.cpp │ ├── Practice │ │ ├── AGELIMIT.py │ │ ├── ATM.cpp │ │ ├── Ambiguous Permutations.cpp │ │ ├── Arranging The Sheep.cpp │ │ ├── Attendence.cpp │ │ ├── Chef And Operators.cpp │ │ ├── Chef and An Ideal Problem.cpp │ │ ├── Chef and Dolls.cpp │ │ ├── Chef and Remissness.cpp │ │ ├── Chef and fruits.cpp │ │ ├── Chef and his Sequence.cpp │ │ ├── Chief_in_Vaccination_Queue.cpp │ │ ├── Ciel and Receipt.cpp │ │ ├── Closing the tweets.cpp │ │ ├── Coins And Triangle.cpp │ │ ├── Cutting recipie.cpp │ │ ├── Decrement OR Increment.cpp │ │ ├── Download file.cpp │ │ ├── Enormous Input Test.cpp │ │ ├── Even or odd.cpp │ │ ├── Farmer And His Plot.cpp │ │ ├── Find Remainder.cpp │ │ ├── Finding Square Roots.cpp │ │ ├── First and Last Digit.cpp │ │ ├── Fit Squares in Triangle.cpp │ │ ├── Food Chain.cpp │ │ ├── GCD and LCM.cpp │ │ ├── Grade The Steel.cpp │ │ ├── Helping Chef.cpp │ │ ├── Id and Ship.cpp │ │ ├── Is it a VOWEL or CONSONANT.cpp │ │ ├── Lapindromes.cpp │ │ ├── Lazy Jem.cpp │ │ ├── Little Elephant and Order.cpp │ │ ├── Lucky Four.cpp │ │ ├── Magical_Doors.cpp │ │ ├── Mahasena.cpp │ │ ├── Mahasena_AMR15A.cpp │ │ ├── Maximum_Light_Up.cpp │ │ ├── Meet In The Median.cpp │ │ ├── Minimum Maximum.cpp │ │ ├── Number Mirror.cpp │ │ ├── PROBDIFF.cpp │ │ ├── Piece of cake.cpp │ │ ├── Primality Test.cpp │ │ ├── Puppy and Sum.cpp │ │ ├── Rectangle.cpp │ │ ├── Second Largest.cpp │ │ ├── Smallest Number of Notes.cpp │ │ ├── Sum of Digits.cpp │ │ ├── Tanu and Head-Bob.cpp │ │ ├── The Block Game.cpp │ │ ├── The Lead Game.cpp │ │ ├── The Smallest Pair.cpp │ │ ├── The_Preparations.cpp │ │ ├── Three Way Communications.cpp │ │ ├── Total Expenses.cpp │ │ ├── Turbo Sort.cpp │ │ ├── Two Numbers.cpp │ │ ├── Valid Triangle.cpp │ │ ├── Valid Triangles.cpp │ │ ├── XMAS Factory.cpp │ │ ├── Xor Equality.cpp │ │ ├── buying_new_tables.cpp │ │ ├── odd_pairs.cpp │ │ └── sums ins a triangle.cpp │ ├── SPLITN.c │ ├── September 2021 Long Challenge │ │ ├── Airline Restrictions │ │ │ ├── airline.cpp │ │ │ └── readme.md │ │ ├── Shufling Parities │ │ │ ├── readme.md │ │ │ └── shuffling_parites.cpp │ │ ├── Travel Pass │ │ │ ├── readme.md │ │ │ └── travel_pass.cpp │ │ └── xor equal.cpp │ ├── SnackDown │ │ ├── lucky_num.cpp │ │ └── readme.md │ ├── Starters 16 (Rated for Div 3) │ │ ├── CHEFMGX.cpp │ │ ├── DiIRECTN.cpp │ │ ├── HCAGMAM1.cpp │ │ └── PASSORFAIL.cpp │ ├── Starters 62 │ │ ├── CHEFSCORE.cpp │ │ ├── FINALSUM.cpp │ │ ├── MAKEMULTIPLE.cpp │ │ ├── MAXDIFFMIN.cpp │ │ ├── SSUBSTR.cpp │ │ └── XJUMP.cpp │ └── starters │ │ ├── BIRDFARM.cpp │ │ ├── CBSPEED.cpp │ │ ├── CHEFSCORE.cpp │ │ ├── Chocholates.cpp │ │ ├── INCREAR.cpp │ │ ├── ISPAR.cpp │ │ ├── MAXDIFFMIN.cpp │ │ ├── Nice_pairs.cpp │ │ ├── Pathpar.cpp │ │ ├── Presents.cpp │ │ ├── SEMCOURSES.cpp │ │ ├── START51 │ │ ├── DiffMedians.cpp │ │ ├── DiffMedians.exe │ │ ├── Dominantelement.cpp │ │ ├── Dominantelement.exe │ │ ├── Finalpopulation.cpp │ │ ├── Finalpopulation.exe │ │ ├── SplitN.cpp │ │ ├── SplitN.exe │ │ ├── TVdiscount.cpp │ │ └── TVdiscount.exe │ │ ├── TSORT.cpp │ │ ├── Taller.cpp │ │ ├── Winnerr.cpp │ │ └── XJUMP.cpp ├── Codeforces │ ├── 1141A.cpp │ ├── 1182A.cpp │ ├── 118B.cpp │ ├── 1206B.cpp │ ├── 1228D.cpp │ ├── 122A Lucky Division.py │ ├── 1330_B.cpp │ ├── 1337_A.cpp │ ├── 1374_D.cpp │ ├── 139A Parents.go │ ├── 1428_C.cpp │ ├── 1467A.cpp │ ├── 1469A.cpp │ ├── 1471A.cpp │ ├── 1487_D.cpp │ ├── 1490B.cpp │ ├── 1511A_Review-site.py │ ├── 1551B1 Wonderful Coloring _1.cpp │ ├── 1551C Interesting Story.cpp │ ├── 1579E1 Permutation Minimization by Deque.cpp │ ├── 1597B-ShiftingSort.cpp │ ├── 1607B.cpp │ ├── 1697_B.cpp │ ├── 1698_C.cpp │ ├── 1699_B.cpp │ ├── 1703_D.cpp │ ├── 1716B Permutation chain │ ├── 1717_A.cpp │ ├── 1717_B.cpp │ ├── 1722_G.cpp │ ├── 1736A.cpp │ ├── 1741A.cpp │ ├── 1741B.cpp │ ├── 1741_C.cpp │ ├── 1742A.cpp │ ├── 1742B.cpp │ ├── 1749A.cpp │ ├── 1A.cpp │ ├── 230_B.cpp │ ├── 282A Bit++.java │ ├── 300_A.cpp │ ├── 365B.cpp │ ├── 401_A.cpp │ ├── 469_A.cpp │ ├── 492_B.cpp │ ├── 500D-NewYearSantaNetwork.cpp │ ├── 515_C.cpp │ ├── 676C Problem C.cpp │ ├── 676C.cpp │ ├── 682_B.cpp │ ├── 746B.cpp │ ├── 766A.cpp │ ├── 824B Tea with Tangerines │ ├── 910C.cpp │ ├── 920E.cpp │ ├── 978C.cpp │ ├── A.2_3 moves.cpp │ ├── A_1359.cpp │ ├── A_1569.cpp │ ├── A_1618.cpp │ ├── A_1647.cpp │ ├── A_1649.cpp │ ├── A_1657.cpp │ ├── A_1668.cpp │ ├── A_1675.cpp │ ├── A_1688.cpp │ ├── A_1696.cpp │ ├── A_1709.cpp │ ├── A_1728.cpp │ ├── A_1739.cpp │ ├── A_318.cpp │ ├── Array Balancing (A) Codeforces 1661.cpp │ ├── B_1042.cpp │ ├── B_1520.cpp │ ├── B_1546.cpp │ ├── B_1574.cpp │ ├── B_1619.cpp │ ├── B_1647.cpp │ ├── B_1675.cpp │ ├── B_1696.cpp │ ├── B_1705.cpp │ ├── B_1713.cpp │ ├── B_1725.cpp │ ├── B_1739.cpp │ ├── B_MEXor_Mixup.cpp │ ├── B_Special_Numbers.cpp │ ├── B_Who_s_Opposite_.cpp │ ├── Bakry_and_Partitioning.cpp │ ├── Beautiful Matrix.cpp │ ├── Beautiful Year.cpp │ ├── Borze.cpp │ ├── C_1574.cpp │ ├── C_1582.cpp │ ├── C_1618.cpp │ ├── C_1675.cpp │ ├── C_1682.cpp │ ├── C_1692.cpp │ ├── C_1697.cpp │ ├── C_1703.cpp │ ├── C_1720.cpp │ ├── C_Sum_of_Cubes.cpp │ ├── Cutting a graph (Codeforces Edu).cpp │ ├── D_1560.cpp │ ├── D_1676.cpp │ ├── D_1690.cpp │ ├── D_1692.cpp │ ├── D_1703.cpp │ ├── DishonestSellers.cpp │ ├── E_1669.cpp │ ├── G_1669.cpp │ ├── G_1722.cpp │ ├── H_1669.cpp │ ├── New Year's Number.py │ ├── Password.cpp │ ├── Presents.cpp │ ├── Pretty Permutations.cpp │ ├── Queue at the School.cpp │ ├── SeatingArrangements.cpp │ ├── Taxi.cpp │ ├── Three Indices.cpp │ ├── Unique Number.cpp │ ├── Vanya_and_Lanterns.cpp │ ├── cyclic_components.cpp │ ├── elections.c++ │ ├── golden plate.cpp │ ├── goodsubarrayseasy.cpp │ ├── make_them_equal.cpp │ ├── makeaequaltob.cpp │ ├── playingwithgcd.cpp │ ├── remove_smallest.cpp │ ├── required_remainder.cpp │ ├── savemice.c++ │ ├── three_friends.cpp │ ├── twins.cpp │ └── wrath.cpp ├── GeeksforGeeks │ ├── Addition_square_matrices.cpp │ ├── Alternative_positive_negative.cpp │ ├── Anagram.cpp │ ├── Armstrong_number.cpp │ ├── Array_subset.cpp │ ├── Arrays_sum.cpp │ ├── At_least_two_greater_elements.cpp │ ├── Average_stream.cpp │ ├── Binary_Search.cpp │ ├── Check_Binary.cpp │ ├── Check_String.cpp │ ├── Check_if_Two_Array_are_equal.cpp │ ├── Complete_the_skills.cpp │ ├── Compound_Interest.cpp │ ├── Convert_String_to_LowerCase.cpp │ ├── Convert_list_of_character_into_string.cpp │ ├── Count_Digits.cpp │ ├── Count_camel.cpp │ ├── Count_type_Characters.cpp │ ├── Cube_root_number.cpp │ ├── Cyclically_rotate_an_array_by_one.cpp │ ├── Delete_alternate_characters.cpp │ ├── Diagonal_sum.cpp │ ├── Display_longest_name.cpp │ ├── Distance_between_two_point.cpp │ ├── Element_Appear_first_Sorted.cpp │ ├── Encoding_Names.cpp │ ├── Even_Odd_Sum.cpp │ ├── Fascinating_Number.cpp │ ├── Find_Min_Max_in_Array.cpp │ ├── Find_difference_between_sum_of_diagonals.cpp │ ├── Find_elements.cpp │ ├── Find_index.cpp │ ├── Find_nth_Term.cpp │ ├── Find_the_median.cpp │ ├── First_element_to_occur_Ktime.cpp │ ├── First_repeating_element.cpp │ ├── Floyd_Traingle.cpp │ ├── Front_back_Transformation.cpp │ ├── Gray_Code.cpp │ ├── Greater_right_side.cpp │ ├── Hour_Clock_Multiplication.cpp │ ├── Identical_matrices.cpp │ ├── Inverse_permutation.cpp │ ├── Java_substring.cpp │ ├── Kth_smallest_element.cpp │ ├── Left_Rotate_Matrix.cpp │ ├── Lower_case_to_upper.cpp │ ├── Make_Distinct_Digit_Array.cpp │ ├── Mean.cpp │ ├── Missing_number_Array.cpp │ ├── Move_all_negative_elements_to_end.cpp │ ├── Multiplication_table.cpp │ ├── Mutiplication_Array.cpp │ ├── Natural_numbers.cpp │ ├── Next_permutation.cpp │ ├── Non_Repeating_element.cpp │ ├── Operators.cpp │ ├── Palindrome_check.cpp │ ├── Palindromic_Array.cpp │ ├── Parallel_or_Perpendicular.cpp │ ├── Party_couple.cpp │ ├── Pattern_of_Strings.cpp │ ├── Pattern_printing.cpp │ ├── Perfect_Arrays.cpp │ ├── Positive_and_negative_elements.cpp │ ├── Power_of_Pow.cpp │ ├── Power_pow_even_Number.cpp │ ├── Print_alternate_elements_Array.cpp │ ├── Print_first_Fibonacci.cpp │ ├── Print_left_element.cpp │ ├── Print_n_number_without_Loop.cpp │ ├── Print_the_left_element.cpp │ ├── Rearranging_array.cpp │ ├── Remove_characters_from_alphanumeric_string.cpp │ ├── Remove_space.cpp │ ├── Remove_vowels_from_string.cpp │ ├── Replace_all_zero_to_five.cpp │ ├── Reverse_a_string.cpp │ ├── Reverse_array_groups.cpp │ ├── Reverse_string.cpp │ ├── Reversing_the_vowels.cpp │ ├── Rotate_by_degree.cpp │ ├── Second_largest.cpp │ ├── Series_AP.cpp │ ├── Small_Factorial.cpp │ ├── Smaller_and_Larger.cpp │ ├── Sort_an_Array_of_0_1_2.cpp │ ├── Sort_by_Set_Bit_Count.cpp │ ├── Sort_the_Array.cpp │ ├── Sorted_matrix.cpp │ ├── Split_Strings.cpp │ ├── String_reciprocal.cpp │ ├── Sum_Of_Digits.cpp │ ├── Sum_Palindrome.cpp │ ├── Sum_of_AP.cpp │ ├── Sum_of_AP_Series.cpp │ ├── Sum_of_Digit_of_Palindrome.cpp │ ├── Sum_of_diagonals.c │ ├── Sum_of_elements_matrix.cpp │ ├── Swap_kth_elements.cpp │ ├── Swap_two_number.cpp │ ├── Swapping_Triangle.cpp │ ├── Traingle_area.cpp │ ├── Transpose_matrix.cpp │ ├── Trapping_Rain_water.cpp │ ├── Triangle_growing_downwards.cpp │ ├── Triangle_shrinking_downwards.cpp │ ├── TwoD_Array.cpp │ ├── Uncommon_string.cpp │ ├── Unique_Numbers.cpp │ ├── Upper_case_conversion.cpp │ ├── Value_equal_index_value.cpp │ ├── Vowel_or_Not.cpp │ ├── Wave_Array.cpp │ ├── ZigZag_Array.cpp │ └── nPr_practice.cpp ├── HackerRank │ ├── Create C++ Class Template Specialization.cpp │ ├── Functions.cpp │ ├── Grid_Search │ │ ├── c++ │ │ │ ├── Solution.png │ │ │ ├── Test_cases.png │ │ │ └── solution.cpp │ │ └── problem.md │ ├── Pairs.cpp │ ├── Pointer.cpp │ ├── SubArrayDiv.Cpp │ ├── Virtual_Functions.cpp │ ├── delete_a_node.cpp │ ├── insert_node_at_head.cpp │ ├── insert_node_at_tail.cpp │ ├── leftRotation.cpp │ ├── min-maxSum.cpp │ └── sum_of_5_numbers.c ├── LeetCode Fresh Start │ ├── 1. Two Sum.cpp │ ├── 1022. Sum of Root To Leaf Binary Numbers.cpp │ ├── 1041. Robot Bounded In Circle.cpp │ ├── 11. Container With Most Water.cpp │ ├── 118. Pascal's Triangle.cpp │ ├── 121. Best Time to Buy and Sell Stock.cpp │ ├── 1290. Convert Binary Number in a Linked List to Integer.cpp │ ├── 1291. Sequential Digits.cpp │ ├── 1305. All Elements in Two Binary Search Trees.cpp │ ├── 1306. Jump Game III.cpp │ ├── 134. Gas Station.cpp │ ├── 1345. The Jump Game IV.cpp │ ├── 1463. Cherry Pickup II.cpp │ ├── 1470. Shuffle the Array.cpp │ ├── 1510. Stone Game IV.cpp │ ├── 1672. Richest Customer Wealth.cpp │ ├── 189. Rotate Array.cpp │ ├── 1920. Build Array from Permutation.cpp │ ├── 1929. Concatenation of Array.cpp │ ├── 20. Valid Parentheses.cpp │ ├── 206. Reverse-linked-list.cpp │ ├── 211. Design Add and Search Words Data Structure.cpp │ ├── 217. Contains Duplicate.cpp │ ├── 312. Burst Balloons.cpp │ ├── 35. Search Insert Position.cpp │ ├── 382. Linked List Random Node.cpp │ ├── 4. Median of Two Sorted Arrays.cpp │ ├── 402. Remove k digits.cpp │ ├── 421. Maximum XOR of Two Numbers in an Array.cpp │ ├── 452. Minimum Number of Arrows to Burst Balloons.cpp │ ├── 455. Assign Cookies.cpp │ ├── 520. Detect Capital.cpp │ ├── 563. Binary Tree Tilt.cpp │ ├── 605. Can Place Flowers.cpp │ ├── 67. Add Binary.cpp │ ├── 701. Insert into a Binary Search Tree.cpp │ ├── 8. String to Integer.cpp │ ├── 84. Largest Rectangle in Histogram.cpp │ ├── 849. Maximize distance to closest person.cpp │ ├── 875. Koko Eating Bananas.cpp │ ├── 902. Numbers At Most N Given Digit Set.cpp │ ├── 941. Valid Mountain Array.cpp │ ├── 973. K Closest Points to Origin.cpp │ ├── 997. Find the town.cpp │ └── Rotate Array.cpp ├── LeetCode Monthly Challenges │ ├── February 2022 │ │ ├── 1. Best Time to Buy and Sell Stock.cpp │ │ ├── 10. Permutations in string.cpp │ │ ├── 10. Word Ladder.cpp │ │ ├── 11. Subsets.cpp │ │ ├── 12. Maximum Depth of Binary Tree.cpp │ │ ├── 13. Single Number.cpp │ │ ├── 14. Swap Nodes in Pairs.cpp │ │ ├── 15. Combination Sum.cpp │ │ ├── 16. Remove K Digits.cpp │ │ ├── 17. Minimize Deviation in Array.cpp │ │ ├── 18. Remove Covered Intervals.cpp │ │ ├── 19. Clone Graph.cpp │ │ ├── 2. Find All Anagrams in a String.cpp │ │ ├── 20. Compare Version Numbers.cpp │ │ ├── 21. Sort List.cpp │ │ ├── 22. Shortest Path Visiting All Nodes.cpp │ │ ├── 23. Maximum width of Binary Tree.cpp │ │ ├── 24. Summary Ranges.cpp │ │ ├── 3. 4Sum II.cpp │ │ ├── 4. Contiguous Array.cpp │ │ ├── 5. Remove duplicates.cpp │ │ ├── 6.Find the Difference.cpp │ │ ├── 7. Add Digits.cpp │ │ ├── 8. K-diff Pairs in an Array.cpp │ │ └── 9. Subarray Sum Equals K.cpp │ └── March 2022 │ │ ├── 1. Counting Bits.cpp │ │ ├── 10. Add Two Numbers.cpp │ │ ├── 11. Rotate List.cpp │ │ ├── 14. Simplify Path.cpp │ │ ├── 2. Is Subsequence.cpp │ │ ├── 3. Arithmetic Slices.cpp │ │ ├── 4. Champagne Tower.cpp │ │ ├── 5. Delete and Earn.cpp │ │ ├── 6. Count All Valid Pickup and Delivery Options.cpp │ │ ├── 7. Merge two Sorted Lists.cpp │ │ ├── 8. Linked List Cycle.cpp │ │ └── 9. Remove duplicate from sorted list.cpp ├── LeetCode │ ├── 0392-is-subsequence.cpp │ ├── 1009-Complement of base 10 integer.cpp │ ├── 1255.Maximum Score Words Formed by Letters │ ├── 1281. Subtract the Product and Sum of Digits of an Integer.cpp │ ├── 1617. Count Subtrees With Max Distance Between Cities.cpp │ ├── 17. Letter Combinations of a Phone Number.cpp │ ├── 171-excel-sheet-column-number.cpp │ ├── 1770-minimum-deletions-to-make-character-frequencies-unique │ ├── 191. Number of 1 Bits │ ├── 23. Merge k Sorted Lists.cpp │ ├── 231. Power of Two.py │ ├── 2sum.py │ ├── 3sum.cpp │ ├── 42. Trapping Rain Water.py │ ├── 430. Flatten a Multilevel Doubly Linked List.py │ ├── 464.CanIWin.cpp │ ├── 502. IPO.py │ ├── 809.ExpressiveWords.cpp │ ├── Add Two Numbers.cpp │ ├── Add two numbers stored in linked list.cpp │ ├── Arithmetic_Slices.cpp │ ├── ArrayfromPermutation.cpp │ ├── Asteroid Collision.py │ ├── Best Time to Buy and Sell Stock III.cpp │ ├── Best Time to Buy and Sell Stock.cpp │ ├── Best_Time_to_Buy_and_Sell_Stock.cpp │ ├── Climbing Stairs.cpp │ ├── Climbing stairs.java │ ├── Clone Graph (LEETCODE).cpp │ ├── Coin change.java │ ├── Daily Temperature (Medium) │ ├── Decode ways.java │ ├── Detect loop in linked list_ayush91985.cpp │ ├── Dungeon Game │ ├── Final Value of Variable After Performing Operations.cpp │ ├── Find The Longest Substring Containing Vowels in Even Counts.java │ ├── Implement strStr().cpp │ ├── Insert_Into_BST.java │ ├── Integer to English Words.cpp │ ├── Jump game.java │ ├── LCS.cpp │ ├── Leetcode_49_Group_Anagrams.cpp │ ├── Leetode_32_Longest_Valid_Parentheses.cpp │ ├── Longest Common Prefix.cpp │ ├── Longest Substring Without Repeating Characters.cpp │ ├── Longest increasing subsequence.java │ ├── Maximize the Confusion of an Exam.java │ ├── Median of two sorted array.cpp │ ├── Merge Two Sorted Lists.cpp │ ├── Move_Zeroes.cpp │ ├── Number of Enclaves.cpp │ ├── Number of Operations to Make Network Connected.cpp │ ├── Number of Pairs of Strings With Concatenation Equal to Target.java │ ├── Palindrome Number.cpp │ ├── PascalTriangle.cpp │ ├── Plus One.cpp │ ├── RangeSumBST.java │ ├── Reconstruct Original Digits from English.cpp │ ├── RegularExpressionMatching.cs │ ├── Remove Duplicates from sorted Array.cpp │ ├── Remove Element.cpp │ ├── Remove Nth Node From End of List │ ├── Remove-nth-child-from-ll.cpp │ ├── Reverse Integer.cpp │ ├── Richest Customer Wealth.cpp │ ├── Roman to Integer.cpp │ ├── Rotate List.cpp │ ├── Rotate-Function.py │ ├── Same Tree.cpp │ ├── Search Insert Position.cpp │ ├── Search in Rotated Sorted Array │ ├── Sliding Window Maximum.cpp │ ├── SpiralMatrix.java │ ├── Square Root Rounded to Nearest Integer │ ├── Sum of Natural numbers using Recursion.cpp │ ├── Sum_of_Even_Numbers_After_Queries.cpp │ ├── TrappingRainwaterProblem.cpp │ ├── Two Sum.cpp │ ├── ValidateBST.java │ ├── Word break.java │ ├── Word-Ladder.cpp │ ├── ZigZag Conversion.cpp │ ├── add2numbers.cpp │ ├── assign_cookies.cpp │ ├── container_with_most_water.cpp │ ├── convert bst to greater tree.cpp │ ├── first missing positive.cpp │ ├── house robber.java │ ├── house robber2.java │ ├── integer_to_roman.java │ ├── longest-palindrome.php │ ├── longest_palindromic_substring.cpp │ ├── longest_substring_without_repeating_character.cpp │ ├── merge k sorted lists.java │ ├── p │ ├── plus_one_pb.py │ ├── roman_to_integer.py │ ├── rotate-image.cpp │ ├── stock_span_problem.cpp │ ├── sudoku.cpp │ ├── valid_sudoku.cpp │ └── word search II.java ├── Leetcode Sheet By Faraz │ └── Array │ │ ├── Easy │ │ ├── . Remove Duplicates from Sorted Array.cpp │ │ ├── Best Time To Buy and Sell.cpp │ │ ├── Merge Sorted Array.cpp │ │ ├── Move Zeros.cpp │ │ ├── Running Sum of 1d Array.cpp │ │ └── Two Sum.cpp │ │ └── Medium │ │ └── Merge Intervals.cpp ├── Length Of Last Word.cpp ├── Median of two sorted arrays of same size └── spoj │ └── Finding the Kth Prime.cpp ├── DSA 450 ├── Arrays │ ├── 1. Reverse the Array.cpp │ ├── 10. Find the duplicate Number.cpp │ ├── 11. Find the duplicate Number.cpp │ ├── 12. Merge Without Extra Space.cpp │ ├── 13.Kadane's Algorithm.cpp │ ├── 14. Merge Interval.cpp │ ├── 15. Next Permutation.cpp │ ├── 16.Count Inversions.cpp │ ├── 17.Best Time to Buy and Sell Stock.cpp │ ├── 18. Count pairs with given sum.cpp │ ├── 19. Find Common Elements.cpp │ ├── 2. Find Maximum and Minimum Element In An Array without using sort function.cpp │ ├── 20.Rearrange array in alternating positive & negative.cpp │ ├── 21.Subarray with zero sum.cpp │ ├── 22. Factorials of large numbers.cpp │ ├── 27.Find the triplet that sum to a given value.cpp │ ├── 29. Trapping Rain Water.cpp │ ├── 3. Kth smallest element.cpp │ ├── 30.Three_Way_Partioning.cpp │ ├── 31. Increasing Triplet Subsequence │ ├── 33.Minimum_no_required_palindrome.cpp │ ├── 34. Median of two arrays.py │ ├── 35. MaximumSumOfSubarray.cpp │ ├── 4. Sort an array of 0s, 1s and 2s.cpp │ ├── 5. Move all negative numbers to beginning.cpp │ ├── 6. Union of two arrays.cpp │ ├── 7. Cyclically rotate an array by one.cpp │ ├── 8. Kadane's Algorithm.cpp │ ├── 9.Minimize the Heights II.cpp │ ├── ArrayRotation.cpp │ └── Maximum of all subarrays of size k.cpp ├── Binary Search Tree │ ├── Balanced_BinaryTree.java │ ├── Bst-implementaion.cpp │ ├── Flatten BST to sorted list │ ├── Largest BST in a Binary Tree in C++ │ ├── Lowest_Common_Ancestor_BST.cpp │ ├── binaryTreeMaxPathSum.cpp │ └── minimum value node in binary search Tree ├── Binary Trees │ ├── How to test the file.txt │ ├── Leftviewoftree.cpp │ ├── PreorderTransversal.cpp │ ├── Reverse_Level_order_traversal.cpp │ ├── Vertical order traversal.cpp │ ├── insertion.cpp │ ├── level_order_traversal.cpp │ └── print_all_left_child_elements.cpp ├── DSA450Readme.md ├── Dynamic Programming │ ├── 01_Knapsack.cpp │ ├── Best_time_to_buy_and_sell_stock.cpp │ ├── Best_time_to_buy_and_sell_stocks_atmax2Transactions.cpp │ ├── Best_time_to_buy_and_sell_stocks_atmaxKTransactions.cpp │ ├── Egg_Dropping_Puzzle.cpp │ ├── LongestIncreasingSubsequence │ ├── Longest_Palindromic_Subsequence.cpp │ ├── Longest_common_subsequence.cpp │ ├── Matrix_Chain_Multiplication_DP.cpp │ ├── UniqueBinarySearchTree.cpp │ └── subset sum problem.cpp ├── Linked List │ ├── Delete Node in a Linked List.cpp │ ├── Merge Sort for Linked Lists.cpp │ ├── addTwoNumbersRepresentedByLinkedList.cpp │ └── middle of linked list.java ├── Matrix │ ├── Common elements in all rows of a given matrix │ ├── MedianRowWiseSorted.cpp │ ├── MedianRowWiseSorted.exe │ └── Spiral traversal of matrix.cpp ├── Queue │ └── ReverseQueUsingStack.java ├── Stack │ ├── Balanced Brackets.cpp │ ├── MaximumRectangularAreaInHistogram.cpp │ ├── Reverse_stack_using_recursion.cpp │ └── theCelebrityProblem.cpp └── String │ ├── Check if string is shuffled substring of another string.cpp │ ├── FirstRepeated.cpp │ ├── Reverse String.cpp │ └── strings are rotations of each other or not.cpp ├── README.md └── Striver CP sheet ├── README.md └── implementation-constructive ├── q1.cpp ├── q10.cpp ├── q11.cpp ├── q12.cpp ├── q13.cpp ├── q14.cpp ├── q15.cpp ├── q16.cpp ├── q2.cpp ├── q3.cpp ├── q4.cpp ├── q5.cpp ├── q6.cpp ├── q7.cpp ├── q8.cpp └── q9.cpp /Accolite/divisible by 13 and 7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | 6 | int n; 7 | cin>>n; 8 | 9 | int arr[n]; 10 | 11 | for(int i=0;i>arr[i]; 14 | } 15 | 16 | int cnt=0,cnt1=0; 17 | 18 | for(int i=0;i 2 | using namespace std; 3 | 4 | //Computing a to the power b using Binary Exponentiation 5 | 6 | long long binpow(long long a, long long b) { 7 | long long res = 1; 8 | while (b > 0) { 9 | if (b & 1) 10 | res = res * a; 11 | a = a * a; 12 | b >>= 1; 13 | } 14 | return res; 15 | } 16 | int main() 17 | { 18 | long long a, b, ans; 19 | cin >> a >> b; 20 | ans = binpow(a, b); // 2 ^ 3 = 8 21 | cout << ans << endl; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /All Algorithms/Kadane's Algorithm/Kadane's Algorithm DP.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | #define INF 1000000000000000000 4 | #define MOD 1000000009; 5 | #define mid(l, u) ((l + u) / 2) 6 | #define rchild(i) (i * 2 + 2) 7 | #define lchild(i) (i * 2 + 1) 8 | using namespace std; 9 | 10 | signed main() { 11 | int n; 12 | cin >> n; 13 | int a[n]; 14 | for (int i = 0; i < n; i++) 15 | cin >> a[i]; 16 | int dp[n]; 17 | dp[0] = a[0]; 18 | int ans = a[0]; 19 | for (int i = 1; i < n; i++) 20 | ans = max(ans, (dp[i] = a[i] + max(dp[i - 1], (int)0))); 21 | cout << ans << endl; 22 | } 23 | 24 | /* 25 | Sample Input: 26 | 8 27 | -2 -3 4 -1 -2 1 5 -3 28 | Sample Output: 29 | 7 30 | */ -------------------------------------------------------------------------------- /All Algorithms/Kadane's Algorithm/Kadane'sAlgorithm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | long long int n,i; 6 | cin>>n; 7 | 8 | long long int arr[n]; 9 | for(int i=0;i>arr[i]; 11 | 12 | long long int cs=arr[0],ms=arr[0]; 13 | 14 | for(i=1;i 2 | #include 3 | 4 | int main() 5 | { 6 | int n; 7 | scanf("%d", &n); 8 | 9 | int arr[n]; 10 | 11 | for(int i=0; i 2 | using namespace std; 3 | using namespace std::chrono; 4 | 5 | int linearSearch(int arr[],int n,int key){ 6 | for (int i = 0; i < n; i++) 7 | { 8 | if (arr[i]==key) 9 | { 10 | return i; 11 | } 12 | 13 | } 14 | 15 | return -1; 16 | } 17 | 18 | 19 | int main() { 20 | int n; 21 | cin>>n; 22 | 23 | int arr[n]; 24 | 25 | for (int i = 0; i < n; i++) 26 | { 27 | cin>>arr[i]; 28 | } 29 | 30 | int key; 31 | cin>>key; 32 | 33 | 34 | 35 | cout<array[i+1]: 7 | array[i], array[i+1] = array[i+1], array[i] 8 | comparisions += 1 9 | if comparisions == 0: 10 | return array 11 | return recursive_sort(array, n-1) 12 | 13 | array = [64, 34, 25, 12, 22, 11, 90] 14 | 15 | new_array = recursive_sort(array, len(array)) 16 | 17 | print("Sorted array :\n", new_array) -------------------------------------------------------------------------------- /All Algorithms/Sorting Algorithm in Python/Recursive_Algorithms/insertion_sort.py: -------------------------------------------------------------------------------- 1 | def insertionSortRecursive(array,n): 2 | if n == 1: 3 | return 4 | insertionSortRecursive(array,n-1) 5 | last = array[n-1] 6 | j = n-2 7 | while (j>=0 and array[j]>last): 8 | array[j+1] = array[j] 9 | j = j-1 10 | array[j+1]=last 11 | 12 | array = [12,11,13,5,6] 13 | insertionSortRecursive(arr, len(array)) 14 | print(array) -------------------------------------------------------------------------------- /All Algorithms/Sorting Algorithm/Count_sort/count_sort.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anupam-kumar-krishnan/Competitive_Programming/6d885c97ed42b338e6ceaf897c92083789e1cc68/All Algorithms/Sorting Algorithm/Count_sort/count_sort.exe -------------------------------------------------------------------------------- /All Algorithms/Sorting Algorithm/DNF_sort/dnf_sort.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anupam-kumar-krishnan/Competitive_Programming/6d885c97ed42b338e6ceaf897c92083789e1cc68/All Algorithms/Sorting Algorithm/DNF_sort/dnf_sort.exe -------------------------------------------------------------------------------- /All Algorithms/Sorting Algorithm/Quick_sort/Quick_sort.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anupam-kumar-krishnan/Competitive_Programming/6d885c97ed42b338e6ceaf897c92083789e1cc68/All Algorithms/Sorting Algorithm/Quick_sort/Quick_sort.exe -------------------------------------------------------------------------------- /All Algorithms/Sorting Algorithm/Selection_Sort.py: -------------------------------------------------------------------------------- 1 | def SelectionSort(L): 2 | size = len(L) 3 | if size < 1: 4 | return(L) 5 | for i in range(size): 6 | min_pos = i 7 | for j in range(i+1,size): 8 | if L[j] < L[min_pos]: 9 | min_pos = j 10 | (L[i],L[min_pos]) = (L[min_pos],L[i]) 11 | return(L) 12 | 13 | a=[] 14 | a=[int(item) for item in input('Enter the list to be sorted: ').split()] 15 | 16 | print('Before Sorting:') 17 | print(a) 18 | SelectionSort(a) 19 | print('After Sorting:') 20 | print(a) 21 | -------------------------------------------------------------------------------- /All Algorithms/Sorting Algorithm/wave_sort/wave_sort.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anupam-kumar-krishnan/Competitive_Programming/6d885c97ed42b338e6ceaf897c92083789e1cc68/All Algorithms/Sorting Algorithm/wave_sort/wave_sort.exe -------------------------------------------------------------------------------- /All Algorithms/String algorithms/KMP.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long ll; 4 | ll pi[1000005]; 5 | 6 | int main() 7 | { 8 | string p,t; 9 | cin>>p>>t; 10 | string st=p+"#"+t; 11 | pi[0]=0; 12 | for(ll i=1;i0&&st[i]!=st[j]) 16 | j=pi[j-1]; 17 | 18 | if(st[i]==st[j]) 19 | j++; 20 | pi[i]=j; 21 | } 22 | ll ans=0; 23 | for(ll i=p.size();i 2 | using namespace std; 3 | 4 | void printRepeating(int arr[], int n) 5 | { 6 | int i; 7 | for (i = 0; i < n; i++) { 8 | if (arr[abs(arr[i])] >= 0) 9 | arr[abs(arr[i])] = -arr[abs(arr[i])]; 10 | else 11 | cout << abs(arr[i]) << " "; 12 | } 13 | } 14 | 15 | int main() 16 | { 17 | int n; 18 | cin>>n; 19 | int arr[n]; 20 | for(int i=0;i>arr[i]; 22 | printRepeating(arr, n); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /All Data Structures/Arrays/22) Factorials of Large Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | namespace mp=boost::multiprecision; 5 | 6 | int main() { 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | mp::cpp_int fact=1; 13 | 14 | for(int i=1; i<=n; i++) 15 | { 16 | fact = fact*i; 17 | } 18 | cout< 2 | using namespace std; 3 | 4 | void rearrange(int arr[], int n) 5 | { 6 | int j = 0; 7 | for (int i = 0; i < n; i++) { 8 | if (arr[i] < 0) { 9 | if (i != j) 10 | swap(arr[i], arr[j]); 11 | j++; 12 | } 13 | } 14 | } 15 | 16 | void displayArray(int arr[], int n) 17 | { 18 | for (int i = 0; i < n; i++) 19 | cout<>n; 26 | int arr[n]; 27 | for(int i=0;i>arr[i]; 29 | rearrange(arr, n); 30 | displayArray(arr, n); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /All Data Structures/Arrays/7) Cyclically rotate an array by one.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | using namespace std; 3 | 4 | void rotate(int arr[], int n) 5 | int main() 6 | { 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n; 12 | cin>>n; 13 | int a[n] , i; 14 | for(i=0;i>a[i]; 16 | rotate(a, n); 17 | for (i = 0; i < n; i++) 18 | cout< 0; i--) 29 | arr[i] = arr[i - 1]; 30 | arr[0] = x; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /All Data Structures/Arrays/A chess game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | while(cin >> n) 7 | { 8 | string j; 9 | cin >> j; 10 | int num = 0; 11 | 12 | for(int i =0;inum)cout<<"Danik"< 2 | using namespace std; 3 | 4 | //function to calculate common factors 5 | 6 | int commonFactors(int a, int b) { 7 | int c=0,k=0; 8 | if(a>c; 23 | cout<<"enter the second number"; 24 | cin>>d; 25 | //call the function 26 | cout<; 2 | 3 | int main(){ 4 | int arr[25],n, product=1; 5 | printf("Enter number of elements: "); 6 | scanf("%d",&n); 7 | for(int i=0;i 2 | int main() 3 | { 4 | int a[10],n,count=0; 5 | printf("Enter the value of n:\n"); 6 | scanf("%d",&n); 7 | printf("Enter the elements:\n"); 8 | for(int i=0;i 2 | using namespace std; 3 | 4 | 5 | int findPeak(int arr[], int n) 6 | { 7 | 8 | if (n == 1) 9 | return 0; 10 | if (arr[0] >= arr[1]) 11 | return 0; 12 | if (arr[n - 1] >= arr[n - 2]) 13 | return n - 1; 14 | 15 | 16 | for (int i = 1; i < n - 1; i++) { 17 | 18 | 19 | if (arr[i] >= arr[i - 1] && arr[i] >= arr[i + 1]) 20 | return i; 21 | } 22 | } 23 | 24 | 25 | int main() 26 | { 27 | int arr[] = { 1, 3, 20, 4, 1, 0 }; 28 | int n = sizeof(arr) / sizeof(arr[0]); 29 | cout << "Index of a peak point is " 30 | << findPeak(arr, n); 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /All Data Structures/Binary Search Tree/BinarySearchTree$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anupam-kumar-krishnan/Competitive_Programming/6d885c97ed42b338e6ceaf897c92083789e1cc68/All Data Structures/Binary Search Tree/BinarySearchTree$Node.class -------------------------------------------------------------------------------- /All Data Structures/Binary Search Tree/BinarySearchTree.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anupam-kumar-krishnan/Competitive_Programming/6d885c97ed42b338e6ceaf897c92083789e1cc68/All Data Structures/Binary Search Tree/BinarySearchTree.class -------------------------------------------------------------------------------- /All Data Structures/Doubly_LL/palindrome: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anupam-kumar-krishnan/Competitive_Programming/6d885c97ed42b338e6ceaf897c92083789e1cc68/All Data Structures/Doubly_LL/palindrome -------------------------------------------------------------------------------- /All Data Structures/Queues/Implement Stack using Queues: -------------------------------------------------------------------------------- 1 | class MyStack { 2 | queue q; 3 | public: 4 | void push(int x) { 5 | int s = q.size(); 6 | q.push(x); 7 | for(int i=0;i Optional[ListNode]: 3 | temp = head 4 | count = 0 5 | while (temp): 6 | temp = temp.next 7 | count +=1 8 | if count<=1: 9 | return None 10 | n = count 11 | mid = n//2 12 | temp = head 13 | while mid>1: 14 | temp = temp.next 15 | mid-=1 16 | temp.next = temp.next.next 17 | return head 18 | -------------------------------------------------------------------------------- /All Data Structures/Sorting/Bubble-sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void Bubblsort(int arr[],int n){ 4 | for(int i=0;iarr[j+1]) 7 | swap(arr[i],arr[j+1]); 8 | } 9 | } 10 | 11 | } 12 | int main() { 13 | int arr[]={3,8,6,4,7,9,2,1,5}; 14 | int n=sizeof(arr)/sizeof(arr[0]); 15 | 16 | for(int i=0;i 2 | #include "trie.h" 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | string words[] = {"hello", "he", "apple", "aple", "news"}; 8 | Trie t; 9 | for (auto word : words) 10 | { 11 | t.insert(word); 12 | } 13 | cout << "Enter the value to be searched :"; 14 | string key; 15 | cin >> key; 16 | cout << t.search(key) << endl; 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Basic Programming/ASCII Value of char.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main () 4 | { 5 | 6 | char x; 7 | cout<<"Enter the character: "; 8 | cin>>x; 9 | 10 | cout<<"ASCII value of "< 2 | #include 3 | 4 | int main(int argc, char const *argv[]) 5 | { 6 | int c=65; 7 | int i,j,k,m; 8 | system("cls"); 9 | for(i=1;i<=5;i++) 10 | { 11 | for(j=5;j>=i;j--) 12 | printf(" "); 13 | for(k=1;k<=i;k++) 14 | printf("%c",c++); 15 | c--; 16 | for(m=1;m 2 | #include 3 | int main(){ 4 | int ch=65; 5 | int i,j,k,m; 6 | system("cls"); 7 | for(i=1;i<=5;i++) 8 | { 9 | for(j=5;j>=i;j--) 10 | printf(" "); 11 | for(k=1;k<=i;k++) 12 | printf("%c",ch++); 13 | ch--; 14 | for(m=1;m 2 | using namespace std; 3 | int main() 4 | { 5 | int n,r,sum=0,temp; 6 | cout<<"Enter the Number= "; 7 | cin>>n; 8 | temp=n; 9 | while(n>0) 10 | { 11 | r=n%10; 12 | sum=sum+(r*r*r); 13 | n=n/10; 14 | } 15 | if(temp==sum) 16 | cout<<"Armstrong Number."< 2 | #define start main 3 | void start() { 4 | printf("Hello"); 5 | } 6 | -------------------------------------------------------------------------------- /Basic Programming/Calculate Sum of Natural Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | int num,sum=0; 7 | 8 | cout<<"Enter the number upto which sum is to be calculated: "; 9 | cin>>num; 10 | 11 | for(int i=0;i>number; 8 | bool isPrime=true; 9 | for(int i=2; i*i<=number; i++) 10 | { 11 | if(number%i==0) 12 | { 13 | isPrime=false; 14 | } 15 | } 16 | if(isPrime) 17 | { 18 | cout<<"Prime Number"< 2 | using namespace std; 3 | int main(){ 4 | char x; 5 | cout<<"Enter a Character: "; 6 | cin>>x; 7 | bool upper,lower; 8 | upper = (x=='A' || x=='E' ||x=='I' ||x=='O' ||x=='U'); 9 | lower = (x=='a' || x=='e' ||x=='i' ||x=='o' ||x=='u'); 10 | 11 | if(!isalpha(x)) 12 | cout<<"Not a Character"; 13 | else if(upper || lower) 14 | cout<<"Vowel"; 15 | else 16 | cout<<"Consonant"; 17 | } 18 | -------------------------------------------------------------------------------- /Basic Programming/Copy Strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string s1, s2; 7 | 8 | cout << "Enter string s1: "; 9 | cin>>s1; 10 | 11 | s2 = s1; 12 | 13 | cout << "s1 = "<< s1 << endl; 14 | cout << "s2 = "<< s2; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Basic Programming/Even or odd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int num; 5 | cout<<"Enter number: "; 6 | cin>>num; 7 | if(num%2==0) 8 | cout<<"Even"; 9 | else 10 | cout<<"Odd"; 11 | } 12 | -------------------------------------------------------------------------------- /Basic Programming/Fahrenheit to Celsius.cpp: -------------------------------------------------------------------------------- 1 | // C++ program that receives temperature in degree Fahrenheit and prints its equivalent value in degree Celsius 2 | 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | float fahrenheit, celsius; 8 | cout<<"Enter the Temperature in Fahrenheit: "; 9 | cin>>fahrenheit; 10 | celsius = (fahrenheit-32)/1.8; 11 | cout<<"\nEquivalent Temperature in Celsius: "< 2 | using namespace std; 3 | int main() { 4 | int a=0,b=1,c,i,n; 5 | cout<<"Enter the number of elements: "; 6 | cin>>n; 7 | cout< 2 | using namespace std; 3 | int main(){ 4 | 5 | cout<<"Char: "< 2 | using namespace std; 3 | int main(){ 4 | int a,b,c; 5 | 6 | cout<<"Enter three numbers: "; 7 | cin>>a>>b>>c; 8 | 9 | if(a>b && a>c) 10 | cout<a && b>c) 12 | cout< 2 | int main() 3 | { 4 | int a, b, c; 5 | scanf("%d %d %d", &a, &b, &c); 6 | if (a > b) 7 | { 8 | if (a > c) 9 | printf("largest: %d\n", a); 10 | else 11 | printf("%d", c); 12 | } 13 | else 14 | { 15 | if (b > c) 16 | printf("largest :%d \n", b); 17 | else 18 | printf("%d", c); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Basic Programming/HCFofTwoNum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int hcf(int num1, int num2){ 5 | if(num1 == 0) 6 | return num2; 7 | 8 | if(num2 == 0) 9 | return num1; 10 | 11 | if(num1 == num2) 12 | return num1; 13 | 14 | if(num1 > num2) 15 | return hcf(num1-num2, num2); 16 | 17 | return hcf(num1, num2-num1); 18 | } 19 | 20 | int main(){ 21 | int num1,num2; 22 | cout<<"Emter 2 numbers : "; 23 | cin>>num1>>num2; 24 | cout<<"HCF of "< 2 | using namespace std; 3 | int main(){ 4 | cout<<"Hellow World!!"< 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | cin>>n; 7 | int arr[n]; 8 | for(int i = 0; i < n; ++i) 9 | { 10 | cout << "Enter Number : "; 11 | cin >> arr[i]; 12 | } 13 | 14 | for(int i = 1;i < n; ++i) 15 | { 16 | if(arr[0] < arr[i]) 17 | arr[0] = arr[i]; 18 | } 19 | cout << "Largest element = " << arr[0]; 20 | } 21 | -------------------------------------------------------------------------------- /Basic Programming/Leap Year or Not.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | int year; 7 | cout<<"Enter Year: "; 8 | cin>>year; 9 | 10 | if(year%4==0 || year%100==0 || year%400==0 ) 11 | cout<<"Leap Year = "< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | 8 | cout << "Enter a positive integer: "; 9 | cin >> n; 10 | 11 | for (int i = 1; i <= 10; ++i) { 12 | cout << n << " * " << i << " = " << n * i << endl; 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Basic Programming/PerfectNumber.cpp: -------------------------------------------------------------------------------- 1 | //A number that is a sum of its positive divisor less than itself is a perfect number. 2 | #include 3 | using namespace std; 4 | int main(){ 5 | //input the number you want to check if it is a perfect number of not 6 | int n; 7 | cin>>n; 8 | int sum=1; 9 | for(int i=2;i*i<=n;i++){ 10 | if(n%i==0){ 11 | sum+=i; 12 | if(n/i!=i) 13 | sum+=n/i; 14 | } 15 | } 16 | if(sum==n) 17 | cout<<"It is a perfect number"< 2 | int main() 3 | { 4 | if(printf("hello world")){} 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /Basic Programming/Program to Add Two Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int num1,num2; 5 | cout<<"Input two numbers: "<>num1>>num2; 7 | cout<<"Addition: "< 2 | using namespace std; 3 | 4 | int main() { 5 | int n, i; 6 | 7 | cout << "Enter a positive integer: "; 8 | cin >> n; 9 | 10 | cout << "Factors of " << n << " are: "; 11 | for(i = 1; i <= n; ++i) { 12 | if(n % i == 0) 13 | cout << i << " "; 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Basic Programming/Program to Print Number Entered by User.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cout<<"Enter a number: "<>n; 7 | cout<<"Print the number: "< 2 | using namespace std; 3 | int main(){ 4 | int num1,num2; 5 | cout<<"Enter two numbers: "; 6 | cin>>num1>>num2; 7 | cout<<"Before Swap: "< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int rows; 7 | 8 | cout << "Enter number of rows: "; 9 | cin >> rows; 10 | 11 | for(int i = rows; i >= 1; --i) 12 | { 13 | for(int j = 1; j <= i; ++j) 14 | { 15 | cout << j << " "; 16 | } 17 | cout << endl; 18 | } 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Basic Programming/Remainder and Quotient.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int num1,num2; 5 | cout<<"Input two numbers: "<>num1>>num2; 7 | cout<<"Quotient: "< 2 | using namespace std; 3 | 4 | int main() { 5 | string line; 6 | string temp = ""; 7 | 8 | cout << "Enter a string: "; 9 | getline(cin, line); 10 | 11 | for (int i = 0; i < line.size(); ++i) { 12 | if ((line[i] >= 'a' && line[i] <= 'z') || (line[i] >= 'A' && line[i] <= 'Z')) { 13 | temp = temp + line[i]; 14 | } 15 | } 16 | line = temp; 17 | cout << "Output String: " << line; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Basic Programming/Unique_hello_world.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define start main 3 | void start() { 4 | printf("Hello"); 5 | } 6 | -------------------------------------------------------------------------------- /Basic Programming/anagram.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | bool areAnagram(string str1, string str2) 4 | { 5 | 6 | int n1 = str1.length(); 7 | int n2 = str2.length(); 8 | 9 | if (n1 != n2) 10 | return false; 11 | 12 | sort(str1.begin(), str1.end()); 13 | sort(str2.begin(), str2.end()); 14 | 15 | for (int i = 0; i < n1; i++) 16 | if (str1[i] != str2[i]) 17 | return false; 18 | return true; 19 | } 20 | 21 | int main() 22 | { 23 | string str1; 24 | string str2; 25 | cin>>str1>>str2; 26 | 27 | 28 | if (areAnagram(str1, str2)) 29 | cout << "The two strings are anagram of each other"; 30 | else 31 | cout << "The two strings are not anagram of each " 32 | "other"; 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Basic Programming/convert binary number to decimal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int convertBinaryToDecimal(long long); 7 | 8 | int main() 9 | { 10 | long long n; 11 | 12 | cout << "Enter a binary number: "; 13 | cin >> n; 14 | 15 | cout << n << " in binary = " << convertBinaryToDecimal(n) << "in decimal"; 16 | return 0; 17 | } 18 | 19 | int convertBinaryToDecimal(long long n) 20 | { 21 | int decimalNumber = 0, i = 0, remainder; 22 | while (n!=0) 23 | { 24 | remainder = n%10; 25 | n /= 10; 26 | decimalNumber += remainder*pow(2,i); 27 | ++i; 28 | } 29 | return decimalNumber; 30 | } 31 | -------------------------------------------------------------------------------- /Basic Programming/duplicate_array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,j,k=0,n; 5 | 6 | int a[10],b[10]; 7 | printf("ENTER THE MARKS OF ARRAY::\n"); 8 | for(i=0;i<10;i++){ 9 | scanf("%d",&a[i]); 10 | } 11 | for(i=0;i<10;i++) 12 | { 13 | for(j=0;j 2 | using namespace std; 3 | 4 | int gcd (int a, int b) { 5 | if (b == 0) 6 | return a; 7 | else 8 | return gcd (b, a % b); 9 | } 10 | int main(void){ 11 | int a,b; cin >> a >> b; 12 | cout << gcd(a,b); 13 | } 14 | -------------------------------------------------------------------------------- /Basic Programming/factorial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cout<<"Enter the number of which you want factorial: "; 7 | cin>>n; 8 | int fact=1; 9 | for(int i=n;i>=1;i--){ 10 | fact=fact*i; 11 | } 12 | if(n==0){ 13 | fact=0; 14 | } 15 | cout<<"The value of "< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int rows; 7 | 8 | cout << "Enter number of rows: "; 9 | cin >> rows; 10 | 11 | for(int i = 1; i <= rows; ++i) 12 | { 13 | for(int j = 1; j <= i; ++j) 14 | { 15 | cout << "* "; 16 | } 17 | cout << "\n"; 18 | } 19 | return 0; 20 | } 21 | ----------------------------------------- 22 | * 23 | * * 24 | * * * 25 | * * * * 26 | * * * * * 27 | -------------------------------------------------------------------------------- /Basic Programming/pyramid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int n,i,j,k; 6 | cout<<"Enter the number of sides: "; 7 | cin>>n; 8 | for(i=1;i<=n;i++){ 9 | for(j=(n-1);j>=i;j--){ 10 | cout<<" "; 11 | } 12 | for(k=1;k<=(2*i-1);k++){ 13 | cout<<"*"; 14 | } 15 | cout< 4 | using namespace std; 5 | 6 | // Function to find sum of series. 7 | float sumOfAP(float a, float d, int n) 8 | { 9 | float sum = 0; 10 | for (int i=0;i 2 | #include 3 | using namespace std; 4 | #define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 5 | 6 | int main(void) { 7 | int moduloNumber = pow(10,9)+7; 8 | int tc; 9 | cin>>tc; 10 | while(tc--) { 11 | int n, count; 12 | cin>>n; 13 | int range = pow(2,n); 14 | 15 | for (int i = 0; i < range ; i++) 16 | { 17 | if ( i^(i+1) == (i+2)^(i+3) ) 18 | count++; 19 | if ( i == n ) 20 | break; 21 | } 22 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int t; 7 | cin>>t; 8 | cout<>am>>bm>>cm>>tm>>a>>b>>c; 13 | if(a>=am && b>=bm && c>=cm && ((a+b+c)>=tm)) 14 | { 15 | cout<<"YES"< 2 | #include 3 | using namespace boost::multiprecision; 4 | using namespace std; 5 | #define int long long int 6 | 7 | signed main() 8 | { 9 | int t; 10 | cin>>t; 11 | while(t--) 12 | { 13 | int n; 14 | cin>>n; 15 | if(n==0) 16 | { 17 | cout<<"1"< 2 | using namespace std; 3 | 4 | int main() { 5 | int a,b,c; 6 | cin>>a; 7 | cin>>b; 8 | cin>>c; 9 | int count=0; 10 | if(a==b) 11 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | float a1,a2,a3,v; 10 | cin>>a1>>a2>>a3>>v; 11 | float var = 100.00/(a1*a2*a3*v); 12 | float k = 9.575; 13 | if(var>=k) 14 | cout<<"NO"< 2 | using namespace std; 3 | #define MOD 1000000007 4 | #define int long long 5 | 6 | int32_t main() 7 | { 8 | 9 | int n; 10 | cin>>n; 11 | 12 | int sum=0; 13 | 14 | for(int i=0;i>x; 18 | 19 | sum=(sum+x+MOD)%MOD; 20 | } 21 | 22 | int q; 23 | cin>>q; 24 | 25 | while(q--) 26 | { 27 | sum=(2*sum)%MOD; 28 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int t; 7 | cin>>t; 8 | while(t--){ 9 | int x,y; 10 | cin>>x>>y; 11 | int m=max(x,y); 12 | int n=min(x,y); 13 | 14 | 15 | if(x==y){ 16 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int t; 7 | cin>>t; 8 | while(t--){ 9 | int x; 10 | cin>>x; 11 | int f=1; 12 | for(int i=1;i*i<=x;i++){ 13 | int j=abs(((2*i)-x)/(2+i)); 14 | 15 | if(j==0)continue; 16 | 17 | int y=(2*i)+(2*j)+(i*j); 18 | if(y==x){ 19 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int t,x; 7 | cin>>t; 8 | for(int i=0;i>x; 11 | cout<<(x*2)< 2 | using namespace std; 3 | 4 | int main() { 5 | int t,x; 6 | cin>>t; 7 | while(t--) 8 | { 9 | cin>>x; 10 | if(x<=100) 11 | cout<100 && x<=1000) 13 | cout<1000 && x<=5000) 15 | cout<5000) 17 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int t; 7 | cin>>t; 8 | while(t--){ 9 | int n; 10 | cin>>n; 11 | int p[n-1]; 12 | int sum = 0,maxi =0; 13 | 14 | 15 | 16 | for(int i = 0;i>p[i]; 18 | sum+=p[i]; 19 | maxi = max(maxi,p[i]); 20 | 21 | 22 | } 23 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | // your code goes here 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | long long n,r = 0; 12 | cin>>n; 13 | vector v(n); 14 | for(int i=0;i>x; 18 | v.push_back(x); 19 | r = r + x; 20 | } 21 | if(find(v.begin(),v.end(),1) != v.end() || r%2) 22 | cout<<"Chef"< 2 | using namespace std; 3 | typedef long long int lli; 4 | 5 | int main() { 6 | // your code goes here 7 | lli T,i,j; 8 | cin>>T; 9 | while(T--){ 10 | lli d,x,y,z; 11 | cin>>d>>x>>y>>z; 12 | lli m1=7*x; 13 | lli m2=y*d + (7-d)*z; 14 | lli r=max(m1,m2); 15 | cout< 2 | using namespace std; 3 | typedef unsigned long long int lli; 4 | 5 | int main() { 6 | lli T,i,j; 7 | cin>>T; 8 | while(T--){ 9 | lli g,c; 10 | cin>>g>>c; 11 | 12 | lli r1=c*c; 13 | lli r2=2L*g; 14 | 15 | lli r=r1/r2; 16 | 17 | cout<> t; 7 | while (t--) 8 | { 9 | long long int n; 10 | cin >> n; 11 | string s1; 12 | cin >> s1; 13 | long long int answer = 0; 14 | for (long long int i = 0; i < n / 2; i++) 15 | { 16 | if (s1[i] != s1[n - i - 1]) 17 | answer++; 18 | } 19 | answer = answer + 1; 20 | cout << answer / 2 << endl; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/CodeChef/October Cook off 2021/CHEFSLP.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int t,n,l,x; 7 | cin>>t; 8 | while (t--) 9 | { 10 | cin>>n>>l>>x; 11 | int r = min(l, n-l); 12 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int a,b,c,d; 11 | cin>>a>>b>>c>>d; 12 | if(a+b+c<=d){ 13 | cout<<1<d || a+c>d || b+c>d){ 18 | cout<<3< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | int a, b, t; 9 | cin >> t; 10 | while (t--) 11 | { 12 | cin >> a >> b; 13 | if (a > 0 && b > 0) 14 | { 15 | cout << "Solution\n"; 16 | } 17 | else if (a == 0) 18 | { 19 | cout << "Liquid\n"; 20 | } 21 | else if 22 | (b == 0) { cout << "Solid\n"; } 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/CodeChef/Practice/AGELIMIT.py: -------------------------------------------------------------------------------- 1 | #Read the number of test cases. 2 | T = int(input()) 3 | for tc in range(T): 4 | # Read integers X, Y and A. 5 | (x, y, a) = map(int, input().split(' ')) 6 | if(a=y): 9 | print('NO') 10 | else: 11 | print('YES') -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/CodeChef/Practice/ATM.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int a; 8 | float b; 9 | 10 | cin>>a>>b; 11 | 12 | if(a % 5 == 0 && a <= b-0.5) 13 | b=b-a-0.50; 14 | 15 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | // your code goes here 7 | int t;cin>>t; 8 | while(t--){ 9 | int n;cin>>n; 10 | string a[n],b[n]; 11 | for(int i=0;i>a[i]>>b[i]; 13 | } 14 | for(int i=0;i=2) 21 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | long long int a,b; 10 | cin>>a>>b; 11 | if(a>b) 12 | cout<<">"< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--) 7 | { 8 | int x,y,k; 9 | cin>>x>>y>>k; 10 | while(k--) 11 | { 12 | if(x>y) 13 | { 14 | y++; 15 | } 16 | else if(x 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin>>t; 8 | while (t--) 9 | { 10 | int n,p,x,y,cx=0,cy=0; 11 | cin>>n>>p>>x>>y; 12 | int arr[101]; 13 | for (int i = 1; i <= n; i++) 14 | cin>>arr[i]; 15 | for (int i = 1; i <= p; i++) 16 | { 17 | if (arr[i]==0) 18 | cx++; 19 | else 20 | cy++; 21 | } 22 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin>>t; 8 | 9 | while(t--) 10 | { 11 | int n,i,ans=0; 12 | cin>>n; 13 | 14 | for(i=11; i>=0; i--) 15 | { 16 | int x = pow(2, i); 17 | ans += n/x; 18 | n %= x; 19 | } 20 | 21 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | // your code goes here 7 | sets; 8 | int n,k,x; 9 | string st; 10 | cin>>n>>k; 11 | for(int i=0;i>st; 14 | if(st!="CLOSEALL") 15 | {cin>>x; 16 | if(s.find(x)==s.end()) 17 | s.insert(x); 18 | else 19 | s.erase(x); 20 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | int t; 8 | cin>>t; 9 | for(int T=0;T>c; 13 | long long int s; 14 | 15 | int ans1=(-1+sqrt(1+4*2*c))/2; 16 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int hcf(int a,int b){ 6 | while (a!=b){ 7 | if (a>b) 8 | a-=b; 9 | else 10 | b-=a; 11 | } 12 | return a; 13 | } 14 | int main() { 15 | int r;cin>>r;while (r--){ 16 | int x;cin>>x;int ar[x]; 17 | for(int i=0;i>ar[i]; 19 | } 20 | //int h =hcf(ar[0],ar[1]); 21 | int h=ar[0]; 22 | for(int i=1;i 2 | using namespace std; 3 | 4 | int main() { 5 | int n; 6 | cin>>n; 7 | if(n%4==0) 8 | n++; 9 | else 10 | n--; 11 | 12 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,k; 10 | cin>>n>>k; 11 | int sol=0; 12 | for(int i=0;i>t>>d; 16 | if(k>=t) 17 | { 18 | k=k-t; 19 | } 20 | else{ 21 | sol=sol+(t-k)*d; 22 | k=0; 23 | } 24 | } 25 | cout< 2 | using namespace std; 3 | 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | 9 | int n, k; 10 | cin >> n >> k; 11 | 12 | int ans = 0; 13 | 14 | for (int i = 0; i < n; i++) { 15 | int t; 16 | cin >> t; 17 | 18 | if (t % k == 0) { 19 | ans++; 20 | } 21 | } 22 | 23 | 24 | cout << ans << "\n"; 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/CodeChef/Practice/Even or odd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | 6 | int num; 7 | cin>>num; 8 | if(num%2==0) 9 | cout<<"Even"; 10 | else 11 | cout<<"Odd"; 12 | 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/CodeChef/Practice/Farmer And His Plot.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int g(int n,int m){ 5 | while(n!=m){ 6 | if(n>m) 7 | n-=m; 8 | else 9 | m-=n; 10 | } 11 | return n; 12 | } 13 | 14 | int main() { 15 | ios_base::sync_with_stdio(false); 16 | cin.tie(NULL); 17 | int t,n,m; 18 | std::cin>>t; 19 | while(t--){ 20 | std::cin>>n>>m; 21 | std::cout<<(m*n)/(g(n,m)*g(n,m))<<"\n"; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/CodeChef/Practice/Find Remainder.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n,i,a,b; 6 | cin>>n; 7 | for(i=0;i>a>>b; 10 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | long long int t; 6 | cin>>t; 7 | while(t--){ 8 | int n; 9 | cin>>n; 10 | int result; 11 | result= sqrt(n); 12 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int t; 8 | cin >> t; 9 | 10 | string num; 11 | while(t--){ 12 | cin >> num; 13 | cout << (num[0]-'0'+(num[num.size()-1]-'0'))< 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int t; cin >> t; 7 | while(t--){ 8 | int s, res=0; 9 | cin>>s; 10 | res = ((s/2)*((s/2)-1))/2; 11 | cout< 2 | using namespace std ; 3 | 4 | #define ff first 5 | #define ss second 6 | #define ull unsigned long long 7 | #define mod 1000000007 8 | #define inf 1e18 9 | #define w(x) int x;cin>>x;while(x--) 10 | #define f(x,y) for( x=0;x>e>>k; 16 | //int c=log(e)/log(k); 17 | int counter=1 ; 18 | float c = e/k; 19 | while(floor(c)>=1){ 20 | counter++; 21 | c=c/k; 22 | } 23 | //cout< 2 | 3 | using namespace std; 4 | 5 | 6 | 7 | int main() 8 | { 9 | long long t,x,y,a=0,b=0,gcd,r,lcm; 10 | cin>>t; 11 | while(t--) 12 | { 13 | 14 | cin>>x>>y; 15 | a=x; 16 | b=y; 17 | while(b!=0) 18 | { 19 | r=a%b; 20 | a=b; 21 | b=r; 22 | } 23 | gcd=a; 24 | lcm=(x*y)/gcd; 25 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int n; 7 | cin>>n; 8 | while(n--) 9 | { int t; 10 | cin>>t; 11 | if(t<10) 12 | cout<<"Thanks for helping Chef!"< 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int n,i; 7 | char c; 8 | cin>>n; 9 | 10 | for(i=0;i>c; 13 | if(c=='d'||c=='D') 14 | cout<<"Destroyer"< 2 | using namespace std; 3 | 4 | int main() { 5 | char vow; 6 | cin>>vow; 7 | if(vow==65||vow==69||vow==73||vow==79||vow==85) 8 | cout<<"Vowel"; 9 | else 10 | cout<<"Consonant"; 11 | // your code goes here 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/CodeChef/Practice/Lapindromes.cpp: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(0, t): 3 | a = input() 4 | if len(a)%2 == 0: 5 | half_1 = a[:len(a)//2] 6 | half_2 = a[(len(a)//2):] 7 | else: 8 | half_1 = a[:(len(a)//2)+1] 9 | half_2 = a[(len(a)//2):] 10 | ans = 0 11 | for i in half_1: 12 | if half_1.count(i) == half_2.count(i): 13 | ans+=1 14 | if ans == len(half_1): 15 | print('YES') 16 | else: 17 | print('NO') 18 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/CodeChef/Practice/Lazy Jem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | long long int n,b,m,k,sum=0; 10 | cin>>n>>b>>m; 11 | while(n>0) 12 | { 13 | if(n%2==0) 14 | { 15 | k=n/2; 16 | } 17 | else 18 | { 19 | k=(n+1)/2; 20 | } 21 | 22 | if(n>1) 23 | { 24 | sum+=(k*m)+b; 25 | } 26 | else if(n==1) 27 | { 28 | sum+=k*m; 29 | } 30 | m=2*m; 31 | n=n-k; 32 | 33 | } 34 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int sizeArr; 6 | cin >> sizeArr; 7 | 8 | int digi, num; 9 | while(sizeArr--){ 10 | scanf("%d", &num); 11 | digi = 0; 12 | while(num>0){ 13 | if(num%10==4){ 14 | digi++; 15 | } 16 | num /= 10; 17 | } 18 | cout << digi << endl; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/CodeChef/Practice/Magical_Doors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t; 8 | cin>>t; 9 | while (t--) 10 | { 11 | int count=0; 12 | string s; 13 | cin>>s; 14 | for (int i = 1; i < s.size(); i++) 15 | { 16 | if (s[i]!=s[i-1]) 17 | count++; 18 | else 19 | continue; 20 | } 21 | if (s[0]=='0') 22 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int n; 6 | cin>>n; 7 | int *p= new int [n]; 8 | for( int i=0; i>p[i]; 10 | } 11 | int odd=0; 12 | int even=0; 13 | for(int i=0; iodd){ 23 | cout<<"READY FOR BATTLE"; 24 | } 25 | else{ 26 | cout<<"NOT READY"; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/CodeChef/Practice/Mahasena_AMR15A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int i,n,arr[100],count_even=0,count_odd=0; 5 | cin>>n; 6 | for(i=0;i>arr[i]; 8 | if(arr[i]%2==0){ 9 | count_even++; 10 | } 11 | else{ 12 | count_odd++; 13 | } 14 | } 15 | if(count_even>count_odd) 16 | { 17 | cout<<"READY FOR BATTLE"; 18 | } 19 | else {cout<<"NOT READY";} 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/CodeChef/Practice/Maximum_Light_Up.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t; 8 | cin>>t; 9 | while (t--) 10 | { 11 | unsigned long long int p,a,b,c,x,y; 12 | cin>>p>>a>>b>>c>>x>>y; 13 | if (a*x + b<=a*y + c) 14 | cout<

2 | #include 3 | using namespace std; 4 | 5 | int lower(int n1,int n2){ 6 | if(n1>n2) return n2; 7 | else return n1; 8 | } 9 | 10 | int main(){ 11 | int t; 12 | 13 | cin>>t; 14 | 15 | while(t--){ 16 | long int n; 17 | cin>>n; 18 | 19 | int arr[n]; 20 | int min=INT_MAX; 21 | 22 | for(int i=0;i>arr[i]; 24 | min=lower(min,arr[i]); 25 | } 26 | 27 | long int ans=min*(n-1); 28 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | long long int n; 7 | cin>>n; 8 | cout< 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int t; 9 | cin >> t; 10 | while (t--) 11 | { 12 | int a[11]; 13 | for (int i = 0; i < 11; i++) 14 | { 15 | a[i] = 0; 16 | } 17 | for (int i = 0; i < 4; i++) 18 | { 19 | int x; 20 | cin >> x; 21 | a[x]++; 22 | cout< 2 | using namespace std; 3 | bool prime(int n) 4 | { 5 | if(n==1) 6 | return false; 7 | for(int i=2;i<=n/2;i++) 8 | { 9 | if(n%i==0) 10 | return false; 11 | } 12 | return true; 13 | } 14 | 15 | int main() 16 | { 17 | int t; 18 | cin>>t; 19 | while (t--) 20 | { 21 | int n; 22 | cin>>n; 23 | if(prime(n)) 24 | cout<<"yes"< 2 | using namespace std; 3 | int sum(int n) 4 | { 5 | int sum=0; 6 | for(int i=1;i<=n;i++) 7 | sum+=i; 8 | 9 | return sum; 10 | } 11 | 12 | int main() 13 | { 14 | int t; 15 | cin>>t; 16 | while (t--) 17 | { 18 | int d, n; 19 | cin>>d>>n; 20 | for(int i=1;i<=d;i++) 21 | { 22 | n=sum(n); 23 | } 24 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int T; 7 | cin>>T; 8 | while(T--) 9 | { 10 | int a,b,c,d; 11 | cin>>a>>b>>c>>d; 12 | if(a==b && c==d) 13 | { 14 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main() { 5 | int t,a,b,c; 6 | cin>>t; 7 | while(t--) 8 | { 9 | cin>>a>>b>>c; 10 | if((a>b&&ac&&aa&&bc&&b 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | for(int i=0;i>b; 11 | 12 | sum+=b/100; 13 | b%=100; 14 | sum+=b/50; 15 | b%=50; 16 | sum+=b/10; 17 | b%=10; 18 | sum+=b/5; 19 | b%=5; 20 | sum+=b/2; 21 | sum+=b%2; 22 | cout << sum << endl; 23 | 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/CodeChef/Practice/Sum of Digits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int N,sum=0,temp; 10 | cin>>N; 11 | while(N > 0) 12 | { 13 | temp= N % 10; 14 | sum = sum + temp; 15 | N = N/10; 16 | } 17 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int n,cy=0,ci=0; 9 | cin>>n; 10 | while(n--){ 11 | char a; 12 | cin>>a; 13 | if(a=='Y'){cy++;} 14 | if(a=='I'){ci++;} 15 | } 16 | if(cy==0 && ci!=0){ 17 | cout<<"INDIAN"< 2 | using namespace std; 3 | typedef long long ll; 4 | int main() { 5 | ll t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | ll n; 10 | cin>>n; 11 | ll rem,rev=0; 12 | ll m=n; 13 | while(m) 14 | { 15 | rem=m%10; 16 | rev=rev*10+rem; 17 | m=m/10; 18 | } 19 | 20 | if(n==rev) 21 | { 22 | cout<<"wins"< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int n; 9 | cin>>n; 10 | int arr[n],i; 11 | for(i = 0;i>arr[i]; 13 | } 14 | sort(arr,arr+n); 15 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin>>t; 8 | while (t--) 9 | { 10 | int m,n,k; 11 | cin>>m>>n>>k; 12 | if (m>n*k) 13 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | long long int t,n,x1,x2,x3,y1,y2,y3,count; 7 | cin>>t; 8 | 9 | while(t--) 10 | { 11 | count=0; 12 | cin>>n; 13 | 14 | cin>>x1>>y1>>x2>>y2>>x3>>y3; 15 | 16 | if(pow(x1-x2,2)+pow(y1-y2,2)<=pow(n,2)) 17 | { 18 | count++; 19 | } 20 | 21 | if(pow(x1-x3,2)+pow(y1-y3,2)<=pow(n,2)) 22 | { 23 | count++; 24 | } 25 | 26 | if(pow(x3-x2,2)+pow(y3-y2,2)<=pow(n,2)) 27 | { 28 | count++; 29 | } 30 | 31 | count>=2?cout<<"yes\n":cout<<"no\n"; 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/CodeChef/Practice/Total Expenses.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | // your code goes here 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | long long int q,p; 11 | double e; 12 | cin>>q>>p; 13 | if(q<=1000){ 14 | e=q*p; 15 | cout< 2 | #define ll long long int 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ll n; 8 | cin>>n; 9 | int a[n]; 10 | for(ll i = 0;i>a[i]; 13 | } 14 | sort(a,a+n); 15 | for(ll i = 0;i 3 | #define ll long long int 4 | using namespace std; 5 | 6 | 7 | int main() 8 | { 9 | ll t; 10 | cin>>t; 11 | while(t--) 12 | { 13 | ll a,b,n,ans; 14 | cin>>a>>b>>n; 15 | if(n%2 == 0) 16 | ans=max(a,b)/min(a,b); 17 | else 18 | ans=max(2*a,b)/min(2*a,b); 19 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int a,b,c; 11 | cin>>a>>b>>c; 12 | if(180==(a+b+c)) 13 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int a,b,c; 9 | cin>>a>>b>>c; 10 | if(a+b+c==180){ 11 | cout<<"YES"< 2 | using namespace std; 3 | #define ll long long 4 | #define mod 1000000007 5 | ll power(ll x,ll y,ll p) 6 | { 7 | ll res = 1; 8 | x = x%p; 9 | 10 | if(x == 0) 11 | return 0; 12 | 13 | while(y>0) 14 | { 15 | if(y & 1) 16 | res = (res*x)%p; 17 | y=y>>1; 18 | x=(x*x)%p; 19 | } 20 | return res; 21 | } 22 | 23 | int main() { 24 | // your code goes here 25 | int t; 26 | cin>>t; 27 | while(t--) 28 | { 29 | ll n; 30 | cin>>n; 31 | ll ans=power(2,n-1,mod); 32 | 33 | cout< 2 | using namespace std; 3 | #define ll long long 4 | #define mod 1000000007 5 | void solve() 6 | { 7 | ll N ; 8 | cin>>N; 9 | 10 | ll even = N / 2; 11 | 12 | ll odd = N - even; 13 | 14 | cout << 2*even * odd<>test; 21 | while(test--) 22 | { 23 | solve(); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/CodeChef/Practice/sums ins a triangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | int t,n; 6 | 7 | cin>>t; 8 | while(t--){ 9 | cin>>n; 10 | int arr[n][n]; 11 | for(int i=0;i>arr[i][j]; 14 | } 15 | } 16 | for(int i=n-2;i>=0;i--){ 17 | for(int j=0;j 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin>>n; 8 | int i = 1; 9 | for(int i = 1;i<=n;i++) 10 | { 11 | int A,B,C,result = 0; 12 | cin>>A>>B>>C; 13 | if(A == 7) result = 1; 14 | if(B == 7) result = 1; 15 | if(C == 7) result = 1; 16 | (result)?cout<<"YES"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int T, n; 6 | cin>>T; 7 | while(T--){ 8 | int check = 0; 9 | cin>>n; 10 | string arr; 11 | cin>>arr; 12 | for(int j =0;j 2 | using namespace std; 3 | 4 | int main(){ 5 | int T, N, X, P, R; 6 | cin>>T; 7 | while(T--){ 8 | cin>>N>>X>>P; 9 | R = (3*X)-(N-X); 10 | if(R>=P){ 11 | cout<<"Pass"< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin >> t; 6 | while(t--){ 7 | string ans="YES"; 8 | int n,x,y; 9 | cin>>n>>x>>y; 10 | if(x>y && y>0){ 11 | ans="NO"; 12 | } 13 | else if(y%x!=0){ 14 | ans="NO"; 15 | } 16 | else if(y>n*x){ 17 | ans="NO"; 18 | } 19 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin >> t; 6 | while(t--){ 7 | int n,q; 8 | cin>>n>>q; 9 | int arr[n]; 10 | int sum = 0; 11 | for(int i=0;i>arr[i]; 13 | sum += arr[i]; 14 | } 15 | for(int i=0;i>l>>r; 18 | if((r-l)%2==0){ 19 | sum++; 20 | } 21 | } 22 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin >> t; 6 | while(t--){ 7 | long long int a,b; 8 | cin>>a>>b; 9 | if(b%a!=0){ 10 | if(b>2*a){ 11 | cout<<"YES"< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin >> t; 6 | while(t--){ 7 | int arr[3]; 8 | cin>>arr[0]>>arr[1]>>arr[2]; 9 | cout<<*max_element(arr,arr+3)-*min_element(arr,arr+3)< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin >> t; 6 | while(t--){ 7 | int ans=0; 8 | int x,y; 9 | cin>>x>>y; 10 | ans=x/y+x%y; 11 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int x,y,z; 10 | cin>>x>>y>>z; 11 | if(z%x==0 && z%y==0) 12 | cout<<"ANY"< 2 | using namespace std; 3 | 4 | int main() { 5 | int x,y; 6 | cin>>x >>y; 7 | if(x>=y) 8 | cout<<"No"< 2 | #define testCase \ 3 | int t; \ 4 | cin >> t; \ 5 | while (t--) 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | testCase 11 | { 12 | int n, x, y; 13 | cin >> n >> x >> y; 14 | if (y % x == 0 && y / x <= n) 15 | cout << "YES" << endl; 16 | else 17 | cout << "NO" << endl; 18 | } 19 | return 0; 20 | } 21 | /* 22 | INPUT 23 | 5 24 | 1 8 4 25 | 3 6 12 26 | 4 5 0 27 | 10 10 100 28 | 8 5 36 29 | 30 | OUTPUT 31 | NO 32 | YES 33 | YES 34 | YES 35 | NO 36 | */ 37 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/CodeChef/starters/Chocholates.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int x,y,z; 9 | cin>> x >> y >>z; 10 | int m,n; 11 | m = (5*x)+(10*y); 12 | // cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int x,y,diff; 10 | cin >>x >>y; 11 | 12 | if(x>y) 13 | { 14 | diff = x-y; 15 | if(diff%2==0) 16 | cout << diff/2 <x) 21 | cout << y-x < 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>> t; 7 | while(t--) 8 | { 9 | long int n,k; 10 | cin >> n >> k; 11 | if(k==1 & n%2!=0) 12 | cout << "odd" < 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin >> t; 7 | while(t--) 8 | { 9 | int n,k; 10 | cin >> n >> k; 11 | if (n%2==0) 12 | { 13 | cout << "Yes" < 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int g; 10 | cin>>g; 11 | g=g-g/5; 12 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int x,y,z; 10 | cin>>x>>y>>z; 11 | cout< 2 | using namespace std; 3 | int main() { 4 | // your code goes here 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,x; 10 | cin>>n; 11 | int i=1,j=n; 12 | while(i 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int t,x,y,z; 7 | cin>>t; 8 | while(t--){ 9 | cin>>x>>y>>z; 10 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int n; 9 | cin>>n; 10 | int result=0; 11 | while(n!=0){ 12 | if(n%2==0){ 13 | n = n/2; 14 | } 15 | else{ 16 | result++; 17 | n = n/2; 18 | } 19 | } 20 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int t,a,b,c,d; 7 | cin>>t; 8 | while(t--){ 9 | cin>>a>>b>>c>>d; 10 | if(a-c>b-d) 11 | cout<<"second"<a-c) 13 | cout<<"first"< 2 | 3 | int main() 4 | { 5 | int a[1000006] ,b[1000006], j, i, t; 6 | scanf("%d",&t); 7 | 8 | for(i = 1; i <= t; i++) { 9 | scanf("%d",&b[i]); 10 | } 11 | 12 | for(i = 1; i <= t; i++) { 13 | a[b[i]]++; 14 | } 15 | 16 | for(j = 1; j < 1000006; j++) { 17 | while(a[j]--) { 18 | printf("%d\n", j); 19 | } 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/CodeChef/starters/Taller.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int x,y; 10 | cin>>x>>y; 11 | if(x>y) 12 | { 13 | cout<<"A"< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int pa,pb,qa,qb,p,q; 10 | cin >> pa >> pb >> qa >> qb; 11 | p = max(pa,pb); 12 | q = max(qa,qb); 13 | if(p 2 | #define testCase \ 3 | int t; \ 4 | cin >> t; \ 5 | while (t--) 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | testCase 11 | { 12 | int x, y; 13 | cin >> x >> y; 14 | cout << x / y + x % y << endl; 15 | } 16 | return 0; 17 | } 18 | /* 19 | INPUT 20 | 4 21 | 4 2 22 | 8 3 23 | 3 4 24 | 2 1 25 | 26 | OUTPUT 27 | 2 28 | 4 29 | 3 30 | 2 31 | */ 32 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/Codeforces/1182A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | #define ll long long 5 | int main(){ 6 | int n; 7 | cin>>n; 8 | 9 | int to_power=n/2; 10 | if(n%2!=0){ 11 | cout<<0< 2 | #define ll long long 3 | const ll N = 1e5+10; 4 | const ll M = 1e7+7; 5 | ll arr[N]; 6 | ll P[M]; 7 | using namespace std; 8 | int main (){ 9 | ll test; 10 | cin>>test; 11 | while(test--){ 12 | ll a, b, c, d; 13 | cin>>a>>b>>c>>d; 14 | cout< 2 | #include 3 | using namespace std; 4 | #define ll long long 5 | 6 | int main(){ 7 | ll int t; 8 | cin>>t; 9 | 10 | while(t--){ 11 | ll int n; 12 | cin>>n; 13 | string s="989"; 14 | if(n<=3){ 15 | cout< 2 | #include 3 | using namespace std; 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | 8 | while(t--){ 9 | string s; 10 | cin>>s; 11 | 12 | int n=s.length(); 13 | 14 | if(n%2==0 && s[0]!=')' && s[n-1]!='('){ 15 | cout<<"YES"< 6 | #define FAST cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0) 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | FAST; 12 | inti(n); 13 | long a[n]; 14 | for(int i=0;i>a[i]; 16 | int t=2,m=2;; 17 | for(int i=2;im) 23 | m=t; 24 | t=2; 25 | } 26 | }if(t>m) 27 | m=t; 28 | cout< 2 | #define ll long long 3 | const ll N = 1e5+10; 4 | const ll M = 1e7+7; 5 | ll arr[N]; 6 | ll P[M]; 7 | using namespace std; 8 | int main (){ 9 | ll n; 10 | cin>>n; 11 | ll a[n]; 12 | for (int i = 0; i < n; i++) 13 | { 14 | cin>>a[i]; 15 | } 16 | sort(a, a+n); 17 | ll count=1; 18 | for (int i = 0; i < n; i++) 19 | { 20 | if (a[i]>=count) 21 | { 22 | count++; 23 | } 24 | 25 | } 26 | cout< 2 | #include 3 | using namespace std; 4 | int main(){ 5 | string str1,str2; 6 | cin>>str1>>str2; 7 | 8 | if(str1==str2){ 9 | cout<<-1< 2 | using namespace std; 3 | 4 | #define ll long long 5 | 6 | int main(){ 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | 11 | #ifndef ONLINE_JUDGE 12 | freopen("input.txt", "r", stdin); 13 | freopen("output.txt", "w", stdout); 14 | #endif 15 | 16 | int t; cin>>t; 17 | while(t--){ 18 | int x, y; cin>>x>>y; 19 | int h = x*x + y*y; 20 | int i = 0; 21 | while(i*i 2 | using namespace std; 3 | 4 | #define ll long long 5 | 6 | int main(){ 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | 11 | #ifndef ONLINE_JUDGE 12 | freopen("input.txt", "r", stdin); 13 | freopen("output.txt", "w", stdout); 14 | #endif 15 | 16 | ll n, k; 17 | cin>>n>>k; 18 | if(n%2 == 0){ 19 | if(k<=n/2) cout<<1+2*(k-1)< 2 | using namespace std; 3 | 4 | #define ll long long 5 | 6 | int main(){ 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | 11 | #ifndef ONLINE_JUDGE 12 | freopen("input.txt", "r", stdin); 13 | freopen("output.txt", "w", stdout); 14 | #endif 15 | 16 | int t; cin>>t; 17 | while(t--){ 18 | ll n; cin>>n; 19 | set s; 20 | for (int i = 1; i * i <= n; i++) 21 | s.insert(i * i); 22 | for (int i = 1; i * i * i <= n; i++) 23 | s.insert(i * i * i); 24 | 25 | cout< 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int x = 0; 9 | for (int i = 1; i <= 5; ++i) 10 | { 11 | for (int j = 1; j <= 5; ++j) 12 | { 13 | cin >> x; 14 | if (x == 1) 15 | { 16 | cout << abs(i - 3) + abs(j - 3) << endl; 17 | } 18 | } 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/Codeforces/Beautiful Year.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int y; 8 | cin >> y; 9 | while (true) 10 | { 11 | y += 1; 12 | int a = y / 1000; 13 | int b = y / 100 % 10; 14 | int c = y / 10 % 10; 15 | int d = y % 10; 16 | if (a != b && a != c && a != d && b != c && b != d && c != d) 17 | { 18 | break; 19 | } 20 | } 21 | cout << y << endl; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/Codeforces/Borze.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | string s,s2; 7 | cin>>s; 8 | int len=s.length(); 9 | for(int i=0;i 2 | using namespace std; 3 | typedef long long ll; 4 | ll powll(ll a){ 5 | return a*a*a; 6 | } 7 | void solve(ll x) { 8 | ll m = cbrt(x); 9 | for(int i=1;i<=m;i++){ 10 | if(cbrt(x-powll(i))==int(cbrt(x-powll(i))) && cbrt(x-powll(i))>=1){ 11 | cout<<"YES\n"; 12 | return; 13 | } 14 | } 15 | cout << "NO\n"; 16 | } 17 | int main() { 18 | 19 | int t; cin >> t; 20 | while (t--) { 21 | ll x; cin >> x; 22 | solve(x); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/Codeforces/New Year's Number.py: -------------------------------------------------------------------------------- 1 | for t in range(int(input())): 2 | n = int(input()) 3 | cnt_2021 = n % 2020 4 | cnt_2020 = (n - cnt_2021) / 2020 - cnt_2021 5 | if cnt_2020 >= 0 and (2020 * cnt_2020) + (2021 * cnt_2021) == n: 6 | print("YES") 7 | else: 8 | print("NO") 9 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/Codeforces/Presents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | cin>>n; 8 | 9 | int arr[n+1]; 10 | int temp; 11 | for(int i=1;i<=n;i++) 12 | { 13 | cin>>temp; 14 | 15 | arr[temp] = i; 16 | } 17 | 18 | for(int i=1;i<=n;i++) 19 | cout< 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, t; 9 | string s; 10 | cin >> n >> t >> s; 11 | while (t--) 12 | { 13 | for (int i = 1; i < n; ++i) 14 | { 15 | if (s[i] == 'G' && s[i-1] == 'B') 16 | { 17 | s[i] = 'B'; 18 | s[i-1] = 'G'; 19 | ++i; 20 | } 21 | } 22 | } 23 | cout << s << endl; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/Codeforces/Three Indices.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve() { 5 | int n; cin >> n; 6 | int a[n] = {}; 7 | for (int i = 0; i < n; i++) 8 | cin >> a[i]; 9 | for (int i = 1; i + 1 < n; i++) { 10 | if (a[i - 1] < a[i] and a[i] > a[i + 1]) { 11 | cout << "YES" << "\n"; 12 | cout << i << ' ' << i + 1 << ' ' << i + 2 << "\n"; 13 | return; 14 | } 15 | } 16 | cout << "NO" << "\n"; 17 | } 18 | 19 | int main() { 20 | int t; cin >> t; 21 | while (t--) solve(); 22 | } -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/Codeforces/Vanya_and_Lanterns.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; cin>>n; 7 | int l; cin>>l; 8 | vectorv(n); 9 | for(int i=0; i>v[i]; 10 | sort(v.begin(),v.end()); 11 | double ans=0; 12 | ans=max(v[0],ans); 13 | ans=max(ans,l-v[n-1]); 14 | for(int i=1; i 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int r,c,p,k,s=0; 8 | cin>>r>>c>>p; 9 | 10 | while(p--) 11 | { 12 | k=(r*c) - (r-2)*(c-2); 13 | s=s+k; 14 | r=r-4; 15 | c=c-4; 16 | 17 | } 18 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int gcd(int a,int b){ 7 | if(b==0) return a; 8 | return gcd(b,a%b); 9 | } 10 | int main(){ 11 | int t;cin>> t; 12 | while(t--){ 13 | int n ; cin >> n; 14 | 15 | vector a(n), b(n+1); 16 | for(int i=0; i < n; ++i) cin >> a[i]; 17 | long long int ans = 0; 18 | int mn = 1e9;int d = 0; 19 | for(int i=n-1;i>=0;--i){ 20 | mn--;d++; 21 | 22 | ans = d; 23 | if(mn < 0) d=0,mn = a[i]; 24 | else if(mn) 25 | } 26 | cout << ans <<'\n'; 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/Codeforces/remove_smallest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std ; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n; 10 | cin>>n; 11 | int a[n]; 12 | for(int i=0;i>a[i]; 15 | } 16 | sort(a,a+n); 17 | int flag=1; 18 | for(int i=0;i 1) 22 | { 23 | flag=0; 24 | break; 25 | } 26 | 27 | } 28 | if(flag) cout<<"YES\n"; 29 | else cout<<"NO\n"; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/Codeforces/required_remainder.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std ; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | long long int x,y,n; 10 | cin>>x>>y>>n; 11 | long long int k=n-(n%x)+y; 12 | while(k>n) 13 | { 14 | k-=x; 15 | } 16 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | long long int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | long long int n,k,i,c=0; 10 | cin>>n>>k; 11 | long long int a[k]; 12 | for(i=0;i>a[i]; 14 | sort(a,a+n); 15 | long long int w=0; 16 | for(i=k-1;i>=0;i--) 17 | { 18 | 19 | if(w>=a[i]) 20 | break; 21 | c++; 22 | long long int k=n-a[i]; 23 | w+=k; 24 | } 25 | cout< 2 | using namespace std ; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | long long a,b,c; 10 | long long arr[3]; 11 | for(auto& x:arr) cin>>x; 12 | sort(arr,arr+3); 13 | a=arr[0];b=arr[1];c=arr[2]; 14 | if((a==b && b==c) || (c-b==1 && b-a==1)) cout<<0< 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n; 8 | cin>>n; 9 | int a[n]; 10 | int sum; 11 | for(int i=0; i>a[i]; 14 | sum += a[i]; 15 | } 16 | sum = sum/2; 17 | sort(a,a+n); 18 | int ans=0; 19 | int cnt = 0; 20 | for(int i=n-1; i>=0; i--) 21 | { 22 | ans += a[i]; 23 | cnt++; 24 | if(ans>sum) 25 | { 26 | break; 27 | } 28 | } 29 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | long int n; 7 | cin>>n; 8 | 9 | long long int a[n]; 10 | for(int i=0;i>a[i]; 12 | 13 | int c=0,k=0,flag=0; 14 | 15 | string s; 16 | 17 | for(int i=n-1;i>0;i--){ 18 | for(int j=i-1;j>=0;j--) 19 | { 20 | if(i-1>=i-a[i]){ 21 | s[k]=i-1; 22 | k++; 23 | flag=1;} 24 | } 25 | } 26 | 27 | if(flag==0) 28 | cout< 2 | #include 3 | using namespace std; 4 | 5 | /* 6 | Add `int max_of_four(int a, int b, int c, int d)` here. 7 | */ 8 | 9 | int main() { 10 | int a, b, c, d; 11 | scanf("%d %d %d %d", &a, &b, &c, &d); 12 | int ans = max_of_four(a, b, c, d); 13 | printf("%d", ans); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/HackerRank/Grid_Search/c++/Solution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anupam-kumar-krishnan/Competitive_Programming/6d885c97ed42b338e6ceaf897c92083789e1cc68/Coding Platforms(codechef,codeforces,etc)/HackerRank/Grid_Search/c++/Solution.png -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/HackerRank/Grid_Search/c++/Test_cases.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anupam-kumar-krishnan/Competitive_Programming/6d885c97ed42b338e6ceaf897c92083789e1cc68/Coding Platforms(codechef,codeforces,etc)/HackerRank/Grid_Search/c++/Test_cases.png -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/HackerRank/Pointer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void update(int *a,int *b) { 4 | // Complete this function 5 | } 6 | 7 | int main() { 8 | int a, b; 9 | int *pa = &a, *pb = &b; 10 | 11 | scanf("%d %d", &a, &b); 12 | update(pa, pb); 13 | printf("%d\n%d", a, b); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/HackerRank/min-maxSum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | vectorv; 7 | long long min=0, max=0; 8 | long long n; 9 | for(int i=0;i<5;i++) 10 | { 11 | cin>>n; 12 | v.push_back(n); 13 | } 14 | sort(v.begin(),v.end()); 15 | for(int i=0;i<4;i++){ 16 | min+=v[i]; 17 | } 18 | for(int i=1;i<5;i++){ 19 | max+=v[i]; 20 | }cout< 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | 8 | int n; 9 | scanf("%d", &n); 10 | int sum=0; 11 | while(n>0){ 12 | int rem=n%10; 13 | sum+=rem; 14 | n/=10; 15 | } 16 | printf("%d",sum); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/1. Two Sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector twoSum(vector& nums, int target) { 4 | for(int i=0 ; ileft and !node->right) 7 | 8 | this->ans += pre * 2 + node->val; 9 | if (node->left) 10 | search(node->left, pre * 2 + node->val); 11 | if (node->right) 12 | search(node->right, pre * 2 + node->val); 13 | } 14 | 15 | int sumRootToLeaf(TreeNode* root) { 16 | search(root); 17 | return this->ans; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/11. Container With Most Water.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxArea(vector& height) { 4 | 5 | int maxi=0; 6 | int i=0;int j=height.size()-1; 7 | while(i& v) { 4 | int minm=v[0], profit=0; 5 | for(int i=1; ival; 7 | head=head->next; 8 | } 9 | return res; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/1291. Sequential Digits.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector sequentialDigits(int l, int h) { 4 | queue q; 5 | for(int i = 1; i <= 9; i++) { 6 | q.push(i); 7 | } 8 | vector ret; 9 | while(!q.empty()) { 10 | int f = q.front(); 11 | q.pop(); 12 | if(f <= h && f >= l) { 13 | ret.push_back(f); 14 | } 15 | if(f > h) 16 | break; 17 | int num = f % 10; 18 | if(num < 9) { 19 | q.push(f * 10 + (num + 1)); 20 | } 21 | } 22 | return ret; 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/1305. All Elements in Two Binary Search Trees.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | vector res; 5 | void dfs(TreeNode *root) 6 | { 7 | if (!root) 8 | return; 9 | res.push_back(root->val); 10 | dfs(root->left); 11 | dfs(root->right); 12 | } 13 | vector getAllElements(TreeNode *root1, TreeNode *root2) 14 | { 15 | dfs(root1); 16 | dfs(root2); 17 | sort(begin(res), end(res)); 18 | return res; 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/1306. Jump Game III.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canReach(vector& A, int i) { 4 | return 0 <= i && i < A.size() && A[i] >= 0 && (!(A[i] = -A[i]) || canReach(A, i + A[i]) || canReach(A, i - A[i])); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/134. Gas Station.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int canCompleteCircuit(vector& gas, vector& cost) { 4 | int current = 0; 5 | int total = 0; 6 | int diff = 0; 7 | int start = 0; 8 | 9 | for(int i = 0; i < gas.size(); i++){ 10 | diff = gas[i] - cost[i]; 11 | 12 | total += diff; 13 | current += diff; 14 | if(current < 0){ 15 | start = i + 1; 16 | current = 0; 17 | } 18 | } 19 | 20 | if(total >= 0){ 21 | return start; 22 | } 23 | 24 | return -1; 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/1470. Shuffle the Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector shuffle(vector& nums, int n) { 4 | int s = 0; 5 | int e = n; 6 | 7 | vector v; 8 | 9 | while(s dp(n + 1); 5 | for(int i = 1; i <= n; i++){ 6 | for(int j = 1; j * j <= i; j++){ 7 | if(!dp[i - j * j]){ 8 | dp[i] = true; 9 | break; 10 | } 11 | } 12 | } 13 | return dp[n]; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/1672. Richest Customer Wealth.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maximumWealth(vector>& accounts) { 4 | 5 | int maxWealthSoFar = 0; 6 | 7 | for (vector& account : accounts) { 8 | 9 | int currCustomerWealth = 0; 10 | for (int money : account) { 11 | currCustomerWealth += money; 12 | } 13 | 14 | maxWealthSoFar = max(maxWealthSoFar, currCustomerWealth); 15 | } 16 | return maxWealthSoFar; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/189. Rotate Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void rotate(vector& nums, int k) { 4 | const int N = nums.size(); 5 | k = k % N; 6 | 7 | reverse(nums.begin(), nums.begin() + N - k); 8 | reverse(nums.begin() + N - k, nums.end()); 9 | 10 | reverse(nums.begin(), nums.end()); 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/1920. Build Array from Permutation.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector buildArray(vector& nums) { 4 | vector ans; 5 | int n= nums.size(); 6 | 7 | for(int i=0; i getConcatenation(vector& nums) { 4 | nums.insert(nums.end(), nums.begin(), nums.end()); 5 | return nums; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/217. Contains Duplicate.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool containsDuplicate(vector& nums) { 4 | unordered_set s; 5 | for(int i=0;i& nums) { 4 | nums.push_back(1); 5 | nums.insert(nums.begin(), 1); 6 | vector > dp(nums.size(), vector(nums.size(), 0)); 7 | for (int i = nums.size() - 3; i >= 0; i --) { 8 | for (int j = i + 2; j < nums.size();j ++) { 9 | for (int k = i + 1; k < j; k ++) 10 | dp[i][j] = max(dp[i][j], dp[i][k] + dp[k][j] + nums[i] * nums[k] * nums[j]); 11 | } 12 | } 13 | return dp[0][nums.size() - 1]; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/35. Search Insert Position.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int searchInsert(vector& nums, int target) { 4 | int n=nums.size(); 5 | int l=0; 6 | int r=n-1; 7 | 8 | while(l<=r){ 9 | int mid=(l+r)/2; 10 | if(nums[mid]==target) return mid; 11 | else if(nums[mid] v; 4 | int n; 5 | Solution(ListNode* head) { 6 | ListNode* cur = head; 7 | while(cur){ 8 | v.push_back(cur->val); 9 | cur=cur->next; 10 | } 11 | n=v.size(); 12 | } 13 | 14 | int getRandom() { 15 | return v[rand()%n]; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/421. Maximum XOR of Two Numbers in an Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findMaximumXOR(vector& nums) { 4 | int res = 0, mask = 0; 5 | for (int i = 31, mask = 0; i >= 0; --i) { 6 | mask |= (1 << i); 7 | unordered_set s; 8 | for (int num : nums) s.insert(num & mask); 9 | int t = res | (1 << i); 10 | for (int prefix : s) 11 | if (s.count(t ^ prefix)) { 12 | res = t; 13 | break; 14 | } 15 | } 16 | return res; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/455. Assign Cookies.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findContentChildren(vector& g, vector& s) { 4 | int i,j,p=0; 5 | 6 | i=g.size()-1; 7 | j=s.size()-1; 8 | 9 | sort(g.begin(),g.end()); 10 | sort(s.begin(),s.end()); 11 | 12 | while(i>=0 && j>=0){ 13 | if(s[j]>=g[i]){ 14 | i--; 15 | j--; 16 | p++; 17 | } 18 | else 19 | i--; 20 | } 21 | return p; 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/520. Detect Capital.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool detectCapitalUse(string word) { 4 | int capitalCount = 0; 5 | for(char ch : word){ 6 | if(ch >= 'A' and ch <= 'Z') capitalCount++; 7 | } 8 | 9 | if(capitalCount == 0 || capitalCount == word.length() || (capitalCount == 1 and word[0] >= 'A' and word[0] <= 'Z')) return true; 10 | 11 | return false; 12 | 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/563. Binary Tree Tilt.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int sum(TreeNode *root,int &tilt){ 4 | if(!root) 5 | return 0; 6 | int left = sum(root->left,tilt); 7 | int right = sum(root->right,tilt); 8 | tilt += abs(left-right); 9 | return (left+right+root->val); 10 | } 11 | int findTilt(TreeNode* root) { 12 | int tilt=0; 13 | sum(root,tilt); 14 | return tilt; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/701. Insert into a Binary Search Tree.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | TreeNode* insertIntoBST(TreeNode* root, int val) { 4 | if(root == NULL) return new TreeNode(val); 5 | if (val > root->val) root->right = insertIntoBST(root->right, val); 6 | else root->left = insertIntoBST(root->left, val); 7 | return root; 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/8. String to Integer.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int myAtoi(string s){ 4 | int i=0,sign=1, ans=0, n=s.size(); 5 | while(i='0' && s[i]<='9'){ 13 | if(ans>INT_MAX/10 || (INT_MAX/10 == ans && s[i]-'0'>7)) return sign==1 ? INT_MAX : INT_MIN; 14 | ans*=10; 15 | ans+= s[i]-'0'; 16 | i++; 17 | } 18 | return ans*sign; 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/997. Find the town.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findJudge(int n, vector>& trust) { 4 | if(trust.empty() && n==1) 5 | return 1; 6 | 7 | vector out(n+1,0); 8 | vector in(n+1,0); 9 | 10 | for(auto edge : trust){ 11 | out[edge[0]]++; 12 | in[edge[1]]++; 13 | } 14 | 15 | for(int i=0;i<=n;i++){ 16 | if(out[i]==0 && in[i]==n-1) 17 | return i; 18 | } 19 | 20 | return -1; 21 | } 22 | 23 | }; 24 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Fresh Start/Rotate Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void rotate(vector& nums, int k) { 4 | const int N = nums.size(); 5 | k = k % N; 6 | 7 | reverse(nums.begin(), nums.begin() + N - k); 8 | reverse(nums.begin() + N - k, nums.end()); 9 | 10 | reverse(nums.begin(), nums.end()); 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/February 2022/1. Best Time to Buy and Sell Stock.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProfit(vector& a) { 4 | vector dp(a.size(), 0); 5 | int minValue = a[0]; 6 | a[0] = 0; 7 | 8 | for (int i = 1; i < a.size(); i++) { 9 | minValue = min(minValue, a[i]); 10 | dp[i] = max(dp[i - 1], a[i] - minValue); 11 | } 12 | 13 | return dp[a.size() - 1]; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/February 2022/11. Subsets.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> subsets(vector& nums) { 4 | vector> ans; 5 | int n = nums.size(); 6 | 7 | for(int i=0; i<(1< sub; 9 | 10 | for(int j=0; jleft), maxDepth(root->right)); 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/February 2022/13. Single Number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int singleNumber(vector& nums) { 4 | if(nums.size()==1) return nums[0]; 5 | int i = 0; 6 | unordered_map mp; 7 | for(i=0; i= num.size()) return "0"; 5 | 6 | std::string res; 7 | res += num[0]; 8 | 9 | for (int i = 1; i < num.size(); i++) { 10 | while (num[i] < res.back() && k-- > 0) { 11 | res.pop_back(); 12 | } 13 | res += num[i]; 14 | } 15 | 16 | if (k > 0) 17 | res.erase(res.size() - k); 18 | 19 | auto it = res.find_first_not_of('0'); 20 | res.erase(0, it); 21 | 22 | return res.empty() ? "0" : res; 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/February 2022/17. Minimize Deviation in Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimumDeviation(vector& nums) { 4 | set ss; 5 | for(auto it:nums){ 6 | if(it & 1) ss.insert(it*2); 7 | else ss.insert(it); 8 | } 9 | int maxi = *ss.rbegin(); 10 | int mini = *ss.begin(); 11 | int ans = INT_MAX; 12 | while(*ss.rbegin()%2==0){ 13 | int currMax = *ss.rbegin(); 14 | ss.erase(currMax); 15 | ss.insert(currMax/2); 16 | ans = min(ans,*ss.rbegin()-*ss.begin()); 17 | } 18 | return ans; 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/February 2022/19. Clone Graph.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void solve(Node* node, unordered_map& mp){ 4 | if(mp[node->val])return; 5 | mp[node->val]=new Node(node->val); 6 | for(Node* x:node->neighbors){ 7 | solve(x,mp); 8 | mp[node->val]->neighbors.push_back(mp[x->val]); 9 | } 10 | } 11 | Node* cloneGraph(Node* node) { 12 | if(node==nullptr) return nullptr; 13 | unordered_map mp; 14 | solve(node,mp); 15 | return mp[1]; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/February 2022/24. Summary Ranges.cpp: -------------------------------------------------------------------------------- 1 | vector summaryRanges(vector& nums) { 2 | const int size_n = nums.size(); 3 | vector res; 4 | if ( 0 == size_n) return res; 5 | for (int i = 0; i < size_n;) { 6 | int start = i, end = i; 7 | while (end + 1 < size_n && nums[end+1] == nums[end] + 1) end++; 8 | if (end > start) res.push_back(to_string(nums[start]) + "->" + to_string(nums[end])); 9 | else res.push_back(to_string(nums[start])); 10 | i = end+1; 11 | } 12 | return res; 13 | } 14 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/February 2022/3. 4Sum II.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int fourSumCount(vector& nums1, vector& nums2, vector& nums3, vector& nums4) { 4 | int count=0; 5 | unordered_map mp; 6 | 7 | for (auto &it1: nums1) 8 | for (auto &it2:nums2) 9 | mp[it1+it2]++; 10 | 11 | for(auto &it3: nums3) 12 | for(auto &it4:nums4) 13 | if(mp.count(0-it3-it4)) count+=mp[0-it3-it4]; 14 | 15 | return count; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/February 2022/5. Remove duplicates.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeDuplicates(vector& nums) { 4 | int i = 0; 5 | for (int n : nums) 6 | if (i < 2 || n > nums[i-2]) 7 | nums[i++] = n; 8 | return i; 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/February 2022/6.Find the Difference.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | char findTheDifference(string s, string t) { 4 | int ans=0; 5 | for(int i=0;i9){ 5 | int temp = num%10; 6 | num = num/10 + temp; 7 | } 8 | return num; 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/February 2022/8. K-diff Pairs in an Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findPairs(vector& nums, int k) { 4 | unordered_map a; 5 | for(int i:nums) 6 | a[i]++; 7 | int ans=0; 8 | for(auto x:a) 9 | { 10 | if(k==0) 11 | { 12 | if(x.second>1) 13 | ans++; 14 | } 15 | else if(a.find(x.first+k)!=a.end()) 16 | ans++; 17 | } 18 | 19 | return ans; 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/February 2022/9. Subarray Sum Equals K.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int subarraySum(vector& nums, int k) { 4 | int ans = 0, sum = 0; 5 | unordered_map map; map[0] = 1; 6 | for(int i = 0; i < nums.size(); i++) { 7 | sum += nums[i]; 8 | ans += map[sum - k]; 9 | map[sum]++; 10 | } 11 | return ans; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/March 2022/1. Counting Bits.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector countBits(int n) { 4 | vector ans; 5 | 6 | 7 | for(int i = 0; i<=n; i++) 8 | { 9 | 10 | int sum = 0; 11 | int num = i; 12 | 13 | while(num != 0) 14 | { 15 | 16 | sum += num%2; 17 | num = num/2; 18 | } 19 | 20 | ans.push_back(sum); 21 | } 22 | 23 | return ans; 24 | } 25 | }; 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/March 2022/11. Rotate List.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | ListNode* rotateRight(ListNode* head, int k) { 4 | if(!head)return head; 5 | int size = 1; 6 | ListNode* tmp = head; 7 | while(tmp->next){ 8 | tmp = tmp->next; 9 | size++; 10 | } 11 | k = size - k % size; 12 | tmp->next = head; 13 | while(k--)tmp = tmp->next; 14 | head = tmp->next; 15 | tmp->next = NULL; 16 | return head; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/March 2022/2. Is Subsequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isSubsequence(string s, string t) { 4 | 5 | int j = 0; 6 | for (int i = 0; i < t.length() && j < s.length(); i++) 7 | if (s[j] == t[i]) 8 | j++; 9 | 10 | return (j == s.length()); 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/March 2022/3. Arithmetic Slices.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numberOfArithmeticSlices(vector& nums) { 4 | int len = nums.size(); 5 | if (len < 3) return 0; 6 | int res = 0, idx = 0; 7 | while (idx < len) { 8 | int idx2 = idx + 2; 9 | while (idx2 < len && nums[idx2] - nums[idx2 - 1] == nums[idx2 - 1] - nums[idx2 - 2]) { 10 | idx2++; 11 | } 12 | int count = idx2 - idx - 2; 13 | res += count * (count + 1) / 2; 14 | idx = idx2 - 1; 15 | } 16 | return res; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/March 2022/5. Delete and Earn.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int deleteAndEarn(vector& nums) { 4 | int n = nums.size(); 5 | vector freq(10001, 0); 6 | for(auto num : nums) freq[num]++; 7 | int max_val = 0, prev_max = 0; 8 | for(int i = 0; i <= 10000; i++) { 9 | int cur_max = max(max_val, prev_max + i * freq[i]); 10 | prev_max = max_val; 11 | max_val = cur_max; 12 | } 13 | return max_val; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/March 2022/6. Count All Valid Pickup and Delivery Options.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countOrders(int n) { 4 | long res = 1, mod = 1000000007; 5 | for(int i = 1; i <=n; ++i) 6 | { 7 | 8 | res *= i; 9 | 10 | res %= mod; 11 | 12 | 13 | res *= (2*i-1); 14 | 15 | } 16 | 17 | 18 | return res % mod; 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/March 2022/8. Linked List Cycle.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool hasCycle(ListNode *head) { 4 | 5 | 6 | if(head == NULL) 7 | return false; 8 | 9 | ListNode *fast = head; 10 | ListNode *slow = head; 11 | 12 | while(fast != NULL && fast ->next != NULL) 13 | { 14 | fast = fast->next->next; 15 | slow = slow->next; 16 | 17 | 18 | if(fast == slow) 19 | return true; 20 | 21 | } 22 | 23 | return false; 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode Monthly Challenges/March 2022/9. Remove duplicate from sorted list.cpp: -------------------------------------------------------------------------------- 1 | ListNode* deleteDuplicates(ListNode* head) { 2 | 3 | ListNode* ans=new ListNode(0); 4 | ListNode* temp=ans; 5 | 6 | while(head!=NULL) 7 | { 8 | bool f=false; 9 | while(head->next!=NULL && head->val==head->next->val){ 10 | head=head->next; 11 | f=true; 12 | } 13 | if(!f){ 14 | temp->next=new ListNode(head->val); 15 | temp=temp->next; 16 | } 17 | head=head->next; 18 | } 19 | return ans->next; 20 | } 21 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/0392-is-subsequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isSubsequence(string t, string s) { 4 | if(s == t) 5 | return true; 6 | int n = s.size(); 7 | int m = t.size(); 8 | int j = 0; 9 | for(int i = 0; i < n; i++){ 10 | if(t[j] == s[i]) 11 | j++; 12 | if(j == t.size()) 13 | return true; 14 | } 15 | return false; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/1009-Complement of base 10 integer.cpp: -------------------------------------------------------------------------------- 1 | //1009. Complement of Base 10 Integer 2 | 3 | //CODE: 4 | 5 | class Solution { 6 | public: 7 | int bitwiseComplement(int n) { 8 | int m=n; 9 | int mask=0; 10 | if(n==0) 11 | { 12 | return 1; 13 | } 14 | while(m!=0) 15 | { 16 | mask=(mask<<1)|1; 17 | m = m >>1; 18 | } 19 | int ans = (~n) & mask; 20 | return ans; 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/1281. Subtract the Product and Sum of Digits of an Integer.cpp: -------------------------------------------------------------------------------- 1 | //1281. Subtract the Product and Sum of Digits of an Integer 2 | 3 | //CODE: 4 | class Solution { 5 | public: 6 | int subtractProductAndSum(int n) { 7 | int sum=0, mul=1; 8 | while(n!=0) 9 | { 10 | int r; 11 | r=n%10; 12 | sum=sum+r; 13 | mul=mul*r; 14 | n=n/10; 15 | } 16 | int result; 17 | result = mul - sum; 18 | return result; 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/171-excel-sheet-column-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int titleToNumber(string columnTitle) { 4 | int result = 0; 5 | for(char c : columnTitle) { 6 | int d = c - 'A' + 1; 7 | result = result * 26 + d; 8 | } 9 | return result; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/1770-minimum-deletions-to-make-character-frequencies-unique: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minDeletions(string s) { 4 | unordered_map mp; 5 | unordered_set freq_set; 6 | int deletions = 0; 7 | 8 | for (char c : s) { 9 | mp[c]++; 10 | } 11 | 12 | for (auto it : mp) { 13 | int freq = it.second; 14 | while (freq > 0 && freq_set.count(freq)) { 15 | deletions++; 16 | freq--; 17 | } 18 | if (freq > 0) { 19 | freq_set.insert(freq); 20 | } 21 | } 22 | 23 | return deletions; 24 | } 25 | 26 | }; 27 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/191. Number of 1 Bits: -------------------------------------------------------------------------------- 1 | //191. Number of 1 Bits 2 | 3 | //CODE: 4 | 5 | class Solution { 6 | public: 7 | int hammingWeight(uint32_t n) { 8 | int count=0; 9 | while(n!=0) 10 | { 11 | if(n&1){ 12 | count++; 13 | } 14 | n=n>>1; 15 | } 16 | return count; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/231. Power of Two.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPowerOfTwo(self, n: int) -> bool: 3 | return n>0 and (n&(n-1)==0) -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/2sum.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(nums, target): 3 | d = {} 4 | for i in range(len(nums)): 5 | if target-nums[i] in d: 6 | return i, d[target-nums[i]] 7 | else: 8 | d[nums[i]] = i 9 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/502. IPO.py: -------------------------------------------------------------------------------- 1 | from heapq import heappop,heappush 2 | class Solution: 3 | def findMaximizedCapital(self, k: int, W: int, Profits: List[int], Capital: List[int]) -> int: 4 | proj = list(zip(Capital,Profits)) 5 | proj.sort(key = lambda a:a[0], reverse = True) 6 | profitHeap = [] # Max Heap 7 | for i in range(k): 8 | while proj and W>=proj[-1][0]: 9 | heappush(profitHeap,-proj.pop()[1]) # - to make it a max heap 10 | if not profitHeap: 11 | break 12 | W+=-heappop(profitHeap) 13 | 14 | return W 15 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Add Two Numbers.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | ListNode* addTwoNumbers(ListNode* l1, ListNode* l2, int carry = 0) { 4 | if (l1 == NULL && l2 == NULL && carry == 0) return NULL; 5 | 6 | int n1 = l1 == NULL ? 0 : l1->val; 7 | int n2 = l2 == NULL ? 0 : l2->val; 8 | 9 | ListNode* node = new ListNode((n1 + n2 + carry) % 10); 10 | carry = (n1 + n2 + carry) / 10; 11 | node->next = addTwoNumbers(l1 ? l1->next : NULL, l2 ? l2->next : NULL, carry); 12 | return node; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/ArrayfromPermutation.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector getConcatenation(vector& nums) 4 | { 5 | int a = nums.size(); 6 | for(int i = 0; i < a; i++) 7 | { 8 | nums.push_back(nums[i]); 9 | } 10 | return nums; 11 | } 12 | }; -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Asteroid Collision.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def asteroidCollision(self, asteroids: List[int]) -> List[int]: 3 | res = [] 4 | for a in asteroids: 5 | if a > 0: 6 | res.append(a) 7 | else: 8 | while len(res) != 0 and res[-1] > 0 and res[-1] < abs(a): 9 | res.pop() 10 | if len(res) == 0 or res[-1] < 0: 11 | res.append(a) 12 | elif res[-1] == abs(a): 13 | res.pop() 14 | return res 15 | 16 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Best Time to Buy and Sell Stock.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProfit(vector& prices) { 4 | int profit = 0; 5 | int maxi = 0; 6 | int res = INT_MIN; 7 | int j = 0; 8 | for(int i = 1; i< prices.size(); i++) 9 | { 10 | profit = prices[i] - prices[i-1]; 11 | maxi += profit; 12 | res = max(res, maxi); 13 | if(maxi < 0) 14 | { 15 | profit = 0; 16 | maxi = 0; 17 | j++; 18 | } 19 | } 20 | if(res > 0) 21 | return res; 22 | else 23 | return 0; 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Best_Time_to_Buy_and_Sell_Stock.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProfit(vector& prices) { 4 | int maxprofit=0; 5 | int minm=prices[0]; 6 | for(int i=0;i& operations) 6 | { 7 | int x=0; 8 | for(auto it:operations) 9 | { 10 | if(it[1]=='+') 11 | x++; 12 | else 13 | x--; 14 | } 15 | return x; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Jump game.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canJump(int[] nums) { 3 | int max = 0; 4 | for (int i = 0; i < nums.length; i ++) { 5 | if (i > max) { 6 | return false; 7 | } 8 | max = Math.max(max, i + nums[i]); 9 | } 10 | return true; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Leetcode_49_Group_Anagrams.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> groupAnagrams(vector& strs) { 4 | vector> result; 5 | unordered_map> mp; 6 | for(string s:strs){ 7 | string key=s; 8 | sort(key.begin(),key.end()); 9 | mp[key].push_back(s); 10 | } 11 | for(auto it:mp) 12 | result.push_back(it.second); 13 | return result; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Longest Common Prefix.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string longestCommonPrefix(vector& strs) { 4 | int i,j,n = strs.size(); 5 | if (n == 0) return ""; 6 | sort(strs.begin() ,strs.begin() + n); 7 | for (j = 0; j < strs[0].size() && j < strs[n - 1].size() && strs[0][j] == strs[n - 1][j]; j++); 8 | return strs[0].substr(0, j); 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Longest Substring Without Repeating Characters.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int lengthOfLongestSubstring(string s) { 4 | int n = s.size(); 5 | int res = 0; 6 | 7 | for (int i = 0; i < n; i++) { 8 | 9 | 10 | vector visited(256); 11 | 12 | for (int j = i; j < n; j++) { 13 | 14 | 15 | if (visited[s[j]] == true) 16 | break; 17 | 18 | else { 19 | res = max(res, j - i + 1); 20 | visited[s[j]] = true; 21 | } 22 | } 23 | 24 | visited[s[i]] = false; 25 | } 26 | return res; 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Longest increasing subsequence.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int lengthOfLIS(int[] nums) { 3 | if(nums==null || nums.length==0) 4 | return 0; 5 | 6 | int[] max = new int[nums.length]; 7 | Arrays.fill(max, 1); 8 | 9 | int result = 1; 10 | for(int i=0; inums[j]){ 13 | max[i]= Math.max(max[i], max[j]+1); 14 | 15 | } 16 | } 17 | result = Math.max(max[i], result); 18 | } 19 | 20 | return result; 21 | }} 22 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Merge Two Sorted Lists.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { 4 | ListNode dummy(INT_MIN); 5 | ListNode *tail = &dummy; 6 | 7 | while (l1 && l2) { 8 | if (l1->val < l2->val) { 9 | tail->next = l1; 10 | l1 = l1->next; 11 | } else { 12 | tail->next = l2; 13 | l2 = l2->next; 14 | } 15 | tail = tail->next; 16 | } 17 | 18 | tail->next = l1 ? l1 : l2; 19 | return dummy.next; 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Number of Pairs of Strings With Concatenation Equal to Target.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int numOfPairs(String[] nums, String target) { 3 | HashSet set = new HashSet<>(); 4 | int n = nums.length; 5 | if(n == 0 ) return 0; 6 | int count = 0; 7 | 8 | for (int i = 0; i < n; i++) { 9 | for(int j=0; j temp) { 16 | int pop = x%10; 17 | preX = x; 18 | x /= 10; 19 | 20 | temp = temp*10 + pop; 21 | } 22 | 23 | if(x == temp || preX == temp) 24 | return true; 25 | else 26 | return false; 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Plus One.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector plusOne(vector& digits) { 4 | int size = digits.size(); 5 | if (!size) return digits; 6 | for(int i = size-1;i>=0;--i){ 7 | if (digits[i]+1 >9){ 8 | digits[i] = digits[i] + 1 - 10; 9 | if(i==0) digits.insert(digits.begin(),1); 10 | } 11 | else{ 12 | digits[i] = digits[i] + 1; 13 | break; 14 | } 15 | } 16 | return digits; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Remove Duplicates from sorted Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeDuplicates(vector& nums) { 4 | if(nums.size()==0) 5 | return 0; 6 | int start=0; 7 | for(int i=1;i& nums, int val) { 4 | int i=0; 5 | while(i INT_MAX/10 || res < INT_MIN/10) 7 | { 8 | return 0; 9 | } 10 | res = res*10+ x%10; 11 | x= x/10; 12 | } 13 | return res; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Richest Customer Wealth.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maximumWealth(vector>& accounts) { 4 | vector sum; 5 | for(int i=0; i values = {{'I', 1}, {'V', 5},{'X', 10},{'L', 50}, 5 | {'C', 100},{'D', 500},{'M', 1000}}; 6 | 7 | int total = 0; 8 | for(int i = 0; i < s.length(); i++){ 9 | 10 | if(values[s[i]] >= values[s[i+1]]){ 11 | total = total + values[s[i]]; 12 | } 13 | 14 | else{ 15 | total = total - values[s[i]]; 16 | } 17 | } 18 | return total; 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Rotate-Function.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def summing(self, nums: list, funct, answer) -> int: 3 | for j in range(len(nums)): 4 | answer += j*nums[j] 5 | funct = max(funct, answer) 6 | 7 | def maxRotateFunction(self, nums: List[int]) -> int: 8 | for i in range(len(nums)): 9 | funct = 0 10 | answer = 0 11 | self.summing(nums, funct, answer) 12 | nums.insert(0, nums[len(nums)-1]) 13 | nums.pop(len(nums)-1) 14 | 15 | if len(nums) == 1: 16 | return 0 17 | 18 | return funct 19 | 20 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Same Tree.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool helper(TreeNode *p , TreeNode*q) 4 | { 5 | if(!p && !q) 6 | return true; 7 | if(!p) 8 | return false; 9 | if(!q) 10 | return false; 11 | 12 | if(p->val!=q->val) 13 | return false; 14 | 15 | return helper(p->right,q->right) && helper(p->left,q->left); 16 | 17 | } 18 | bool isSameTree(TreeNode* p, TreeNode* q) { 19 | return helper(p,q); 20 | 21 | } 22 | 23 | }; 24 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Search Insert Position.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int binsrch(int arr[], int l, int r ,int& k){ 4 | while(l<=r){ 5 | int mid = (l + r) /2; 6 | 7 | if(arr[mid] == k){ 8 | return mid; 9 | } 10 | 11 | if(arr[mid] > k){ 12 | r = mid -1; 13 | } 14 | if(arr[mid] < k){ 15 | l = mid +1; 16 | } 17 | } 18 | return l; 19 | } 20 | 21 | int searchInsert(vector& nums, int target) { 22 | int* arr = &nums[0]; 23 | return binsrch(arr, 0, nums.size() -1, target); 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Search in Rotated Sorted Array: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int search(vector& nums, int t) { 4 | vector> v; 5 | for(int i=0;iv[mid].first) i=mid+1; 13 | else if(t 2 | using namespace std; 3 | 4 | int add(int n); 5 | 6 | int main() { 7 | int n; 8 | 9 | cout << "Enter a positive integer: "; 10 | cin >> n; 11 | 12 | cout << "Sum = " << add(n); 13 | 14 | return 0; 15 | } 16 | 17 | int add(int n) { 18 | if(n != 0) 19 | return n + add(n - 1); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/Two Sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector twoSum(vector& nums, int target) { 4 | map m; 5 | vector v; 6 | for(int i=0;i& g, vector& s) { 4 | sort(g.begin(), g.end()); 5 | sort(s.begin(), s.end()); 6 | int cnt=0, i=0, j=0; 7 | 8 | while(is[j]) { 14 | j++; 15 | } 16 | } 17 | return cnt; 18 | 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/container_with_most_water.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxArea(vector& h) { 4 | int l=0; 5 | int r=h.size()-1; 6 | int area=0; 7 | while(lright); 9 | total += root->val; 10 | root->val = total; 11 | convertBST(root->left); 12 | return root; 13 | } 14 | }; -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/first missing positive.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int firstMissingPositive(vector& nums) { 4 | int n = nums.size(); 5 | for(int i = 0; i < n; i++){ 6 | while(nums[i] > 0 && nums[i] < n && nums[i] != nums[nums[i] - 1]){ 7 | swap(nums[i], nums[nums[i] - 1]); 8 | } 9 | } 10 | 11 | for(int i = 0; i < n; i++){ 12 | if(nums[i] != i + 1){ 13 | return i + 1; 14 | } 15 | } 16 | return n + 1; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/house robber.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | public int rob(int[] nums) { 3 | if(nums ==null || nums.length == 0) return 0; 4 | if(nums.length == 1) return nums[0]; 5 | 6 | int prev=0; // res[i-1] 7 | int cur=0; // res[i]; 8 | 9 | 10 | for(int i=0; i< nums.length;i++){ 11 | int m = prev, n = cur; 12 | cur = prev + nums[i]; 13 | prev = Math.max(m,n); 14 | } 15 | 16 | return Math.max(cur,prev); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/LeetCode/longest_substring_without_repeating_character.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int lengthOfLongestSubstring(string s) { 4 | unordered_map>m; 5 | int c=0,mx=0,i=0,pos=0; 6 | for(i=0;i 2 | 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int peakIndexInMountainArray(vector& arr) { 8 | int s=0; 9 | int e=arr.size()-1; 10 | int mid=s+(e-s)/2; 11 | while(s a1 = {1,3,5,7,4,2}; 27 | x = s1.peakIndexInMountainArray(a1); 28 | cout< int: 3 | roman = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000} 4 | n = len(s) 5 | num = 0 6 | for i in range(n): 7 | if i+1>& matrix) { 4 | int n = matrix.size(); 5 | int m = matrix[0].size(); 6 | 7 | for(int i = 1; i < n; i++){ 8 | for(int j = 0; j < i; j++){ 9 | swap(matrix[i][j], matrix[j][i]); 10 | } 11 | } 12 | for(int i = 0; i < n; i++){ 13 | reverse(matrix[i].begin(), matrix[i].end()); 14 | } 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/Leetcode Sheet By Faraz/Array/Easy/. Remove Duplicates from Sorted Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeDuplicates(vector& nums) { 4 | if(nums.size()==0) 5 | return 0; 6 | int start=0; 7 | for(int i=1;i& prices) { 4 | int maxPro = 0, minPrice = INT_MAX; 5 | for(int i = 0; i < prices.size(); i++) { 6 | minPrice = min(minPrice, prices[i]); 7 | maxPro = max(prices[i] - minPrice, maxPro); 8 | } 9 | return maxPro; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/Leetcode Sheet By Faraz/Array/Easy/Move Zeros.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void moveZeroes(vector& nums) 4 | { 5 | for(int i=0,next=0;i runningSum(vector &nums) { 4 | vector result = {nums[0]}; 5 | 6 | for (int i = 1; i < nums.size(); i++) { 7 | result.push_back(result.back() + nums[i]); 8 | } 9 | return result; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/Leetcode Sheet By Faraz/Array/Easy/Two Sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector twoSum(vector& nums, int target) { 4 | for(int i = 0; i < nums.size(); i++){ 5 | for(int j = i + 1; j < nums.size(); j++){ 6 | if(nums[i] + nums[j] == target){ 7 | return {i, j}; 8 | } 9 | } 10 | } 11 | return {}; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/Leetcode Sheet By Faraz/Array/Medium/Merge Intervals.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Coding Platforms(codechef,codeforces,etc)/Length Of Last Word.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int lengthOfLastWord(string s) { 4 | int ans=0; 5 | for(int i=s.size()-1;i>=0;i--) 6 | { 7 | if(s[i]==32 && ans>0) 8 | return ans; 9 | if(s[i]!=32) 10 | ans++; 11 | } 12 | return ans; 13 | 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /DSA 450/Arrays/1. Reverse the Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void rvereseArray(int arr[], int start, int end) 5 | { 6 | while (start < end) 7 | { 8 | int temp = arr[start]; 9 | arr[start] = arr[end]; 10 | arr[end] = temp; 11 | start++; 12 | end--; 13 | } 14 | } 15 | 16 | void printArray(int arr[], int size) 17 | { 18 | for (int i = 0; i < size; i++) 19 | cout << arr[i] << " "; 20 | cout << endl; 21 | } 22 | 23 | int main() 24 | { 25 | int n; 26 | cin>>n; 27 | int arr[n]; 28 | 29 | for(int i=0;i>arr[i] 31 | 32 | printArray(arr, n); 33 | rvereseArray(arr, 0, n-1); 34 | printArray(arr, n); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /DSA 450/Arrays/10. Find the duplicate Number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findDuplicate(vector& nums) { 4 | sort(nums.begin(), nums.end()); 5 | for (int i = 1; i < nums.size(); i++) { 6 | if (nums[i] == nums[i - 1]) 7 | return nums[i]; 8 | } 9 | return -1; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /DSA 450/Arrays/11. Find the duplicate Number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findDuplicate(vector& nums) { 4 | sort(nums.begin(), nums.end()); 5 | for (int i = 1; i < nums.size(); i++) { 6 | if (nums[i] == nums[i - 1]) 7 | return nums[i]; 8 | } 9 | return -1; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /DSA 450/Arrays/16.Count Inversions.cpp: -------------------------------------------------------------------------------- 1 | // 2 4 1 3 5 2 | // 1 4 2 3 5 - 1 iteration 3 | // 1 2 4 3 5 - 2 iteration 4 | // 1 2 3 4 5 - 3 iteration 5 | 6 | #include 7 | using namespace std; 8 | 9 | int getInvCount(int arr[], int n) 10 | { 11 | int inv_count = 0; 12 | for (int i = 0; i < n - 1; i++) 13 | for (int j = i + 1; j < n; j++) 14 | if (arr[i] > arr[j]) 15 | inv_count++; 16 | 17 | return inv_count; 18 | } 19 | 20 | int main() 21 | { 22 | int n; 23 | cin>>n; 24 | int arr[n]; 25 | for(int i=0;i>arr[i]; 27 | cout << " Number of inversions are " 28 | << getInvCount(arr, n); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /DSA 450/Arrays/17.Best Time to Buy and Sell Stock.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProfit(vector& prices) { 4 | int maxPro = 0, minPrice = INT_MAX; 5 | for(int i = 0; i < prices.size(); i++) { 6 | minPrice = min(minPrice, prices[i]); 7 | maxPro = max(prices[i] - minPrice, maxPro); 8 | } 9 | return maxPro; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /DSA 450/Arrays/18. Count pairs with given sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,k; 7 | cin>>n>>k; 8 | 9 | int arr[n]; 10 | for(int i=0;i>arr[i]; 12 | int cnt=0; 13 | 14 | for(int i=0;i 2 | using namespace std; 3 | 4 | bool subArrayExists(int arr[], int n) 5 | { 6 | unordered_set sumSet; 7 | int sum = 0; 8 | for (int i = 0; i < n; i++) 9 | { 10 | sum += arr[i]; 11 | 12 | if (sum == 0 13 | || sumSet.find(sum) 14 | != sumSet.end()) 15 | return true; 16 | 17 | sumSet.insert(sum); 18 | } 19 | return false; 20 | } 21 | 22 | 23 | int main() 24 | { 25 | int n; 26 | cin>>n; 27 | 28 | int arr[n]; 29 | for(int i=0;i>arr[i]; 31 | 32 | if (subArrayExists(arr, n)) 33 | cout << "Yes"; 34 | else 35 | cout << "No"; 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /DSA 450/Arrays/22. Factorials of large numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t; cin>>t; 6 | while(t--){ 7 | int n; cin>>n; 8 | mp::cpp_int fact=1; 9 | 10 | for(int i=1; i<=n; i++){ 11 | fact = fact*i; 12 | } 13 | cout< 2 | using namespace std; 3 | 4 | int maxWater(int arr[], int n) 5 | { 6 | 7 | int res = 0; 8 | 9 | for (int i = 1; i < n-1; i++) { 10 | 11 | 12 | int left = arr[i]; 13 | for (int j=0; j& nums) { 4 | int n = nums.size(); 5 | if(n<3) return false; 6 | long long var1= nums[0],var2=3e9; 7 | for(int i=1;ivar2){ 9 | return true; 10 | } 11 | if(nums[i]>var1){ 12 | var2 = nums[i]; 13 | } 14 | else if(nums[i] 2 | using namespace std; 3 | class Solution{ 4 | public: 5 | int doUnions(int a[],int n,int b[],int m){ 6 | set s; 7 | for(int i=0;i>n>>m; 21 | 22 | int a[n],b[m]; 23 | for(int i=0;i>a[n]; 25 | 26 | for(int j=0;j>b[j]; 28 | 29 | Solution ob; 30 | cout << ob.doUnions(a,n,b,m); 31 | } 32 | -------------------------------------------------------------------------------- /DSA 450/Arrays/7. Cyclically rotate an array by one.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void rotate(int arr[], int n){ 4 | int temp = arr[n-1]; 5 | for(int i=n-2;i>=0;i--){ 6 | arr[i+1]=arr[i]; 7 | } 8 | arr[0]=temp; 9 | } 10 | int main() 11 | { 12 | 13 | int n; 14 | cin>>n; 15 | int a[n], i; 16 | 17 | for(i=0;i>a[i]; 19 | 20 | rotate(a,n); 21 | 22 | for(i=0;idata>n1 && root->data>n2){ 7 | return LCA(root->left, n1, n2); 8 | } 9 | else if(root->datadataright, n1, n2); 11 | } 12 | else{ 13 | return root; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DSA 450/Binary Trees/How to test the file.txt: -------------------------------------------------------------------------------- 1 | Code is broken into 2 parts : 2 | 1. Create binary tree for each testcase. 3 | 2. Print all the left child elements in binary tree. 4 | 5 | Detail description : 6 | 1. Create binary tree for each testcase : 7 | #1 - first input is number of testcases. 8 | #2 - Enter the size of array. 9 | #3 - Enter the elements in array if input value is 0 then it means particular node is NULL. 10 | 11 | 2. Print all the left child elements of binary tree : 12 | #1 - using queue 13 | #2 - Time complexity : O(n) 14 | #3 - Space complexity : O(n) 15 | -------------------------------------------------------------------------------- /DSA 450/DSA450Readme.md: -------------------------------------------------------------------------------- 1 | # 💻DSA-450💻 2 | ![dsa44](https://user-images.githubusercontent.com/69143883/123937540-e6d4a100-d9b3-11eb-8be0-08525ad401d6.png) 3 | -------------------------------------------------------------------------------- /DSA 450/Dynamic Programming/Best_time_to_buy_and_sell_stock.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int maximumProfit(vector &prices) 7 | { 8 | int n = prices.size(); 9 | int mini = prices[0]; 10 | int profit = 0; 11 | for (int i = 1; i < n; i++) 12 | { 13 | int cost = prices[i] - mini; 14 | profit = max(profit, cost); 15 | mini = min(mini, prices[i]); 16 | } 17 | return profit; 18 | } 19 | 20 | int main() { 21 | 22 | vector Arr ={7,1,5,3,6,4}; 23 | 24 | cout<<"The maximum profit by selling the stock is "< 2 | using namespace std; 3 | 4 | int lcs(char *X, char *Y, int m, int n) 5 | { 6 | int L[m + 1][n + 1]; 7 | 8 | for (int i = 0; i <= m; i++) 9 | { 10 | for (int j = 0; j <= n; j++) 11 | { 12 | if (i == 0 || j == 0) 13 | L[i][j] = 0; 14 | 15 | else if (X[i - 1] == Y[j - 1]) 16 | L[i][j] = L[i - 1][j - 1] + 1; 17 | 18 | else 19 | L[i][j] = max(L[i - 1][j], L[i][j - 1]); 20 | } 21 | } 22 | 23 | return L[m][n]; 24 | } 25 | 26 | int main() 27 | { 28 | 29 | char X[] = "AGGTAB"; 30 | char Y[] = "GXTXAYB"; 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /DSA 450/Dynamic Programming/UniqueBinarySearchTree.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long int fun(int n,int r,vector>&dp){ 4 | if(n==r) return 1; 5 | if(r==0) return 1; 6 | 7 | if(dp[n][r]!=-1) return dp[n][r]; 8 | return dp[n][r]=fun(n-1,r,dp)+0LL+fun(n-1,r-1,dp); 9 | } 10 | int numTrees(int n) { 11 | 12 | int a=2*n; 13 | vector>dp(a+3,vector(n+2,-1)); 14 | return fun(a,n,dp)/(n+1); 15 | 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /DSA 450/Matrix/MedianRowWiseSorted.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anupam-kumar-krishnan/Competitive_Programming/6d885c97ed42b338e6ceaf897c92083789e1cc68/DSA 450/Matrix/MedianRowWiseSorted.exe -------------------------------------------------------------------------------- /DSA 450/String/Reverse String.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void reverseString(vector& s) { 4 | int left=0; 5 | int right=s.size()-1; 6 | while(left 2 | using namespace std; 3 | 4 | bool areRotations(string str1, string str2) 5 | { 6 | 7 | if (str1.length() != str2.length()) 8 | return false; 9 | 10 | string temp = str1 + str1; 11 | return (temp.find(str2) != string::npos); 12 | } 13 | 14 | int main() 15 | { 16 | string str1 = "AACD", str2 = "ACDA"; 17 | if (areRotations(str1, str2)) 18 | printf("Strings are rotations of each other"); 19 | else 20 | printf("Strings are not rotations of each other"); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # _Competitive Programming_ 2 | 3 | ## _Programming👨‍💻 Questions on_ 4 | - _BinarySearch_ 5 | - _LeetCode_ 6 | - _CodeChef_ 7 | - _Codeforces_ 8 | - _DSA 450_ 9 | -------------------------------------------------------------------------------- /Striver CP sheet/README.md: -------------------------------------------------------------------------------- 1 | # Striver's CP sheet 2 | 3 | Access the questions at [Striver's CP sheet](https://takeuforward.org/interview-experience/strivers-cp-sheet/?utm_source=youtube&utm_medium=striver&utm_campaign=yt_video). -------------------------------------------------------------------------------- /Striver CP sheet/implementation-constructive/q1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int x=0,t; 7 | cin>>t; 8 | string s; 9 | //string plus = "++",minus = "--"; 10 | while(t--){ 11 | cin>>s; 12 | if(s[0]=='+' || s[2]=='+')x++; 13 | else x--; 14 | } 15 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n,tmp,flag=0; 6 | cin>>n; 7 | int i; 8 | for(i=0;i>tmp; 10 | if(tmp) 11 | flag=1; 12 | } 13 | if(flag) 14 | cout<<"HARD"; 15 | else 16 | cout<<"EASY"; 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Striver CP sheet/implementation-constructive/q11.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | cin>>n; 8 | int arr[n]; 9 | int i; 10 | for(i=0;i>arr[i]; 12 | int c=0; 13 | while(true){ 14 | if(c==n)break; 15 | for(i=0;i 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | string n; 8 | cin>>n; 9 | int count=0; 10 | while(n!="") 11 | { 12 | int a=n[0]; 13 | if(a=='7' || a=='4') 14 | count++; 15 | n=n.substr(1); 16 | } 17 | if(count==4||count==7) 18 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,a,b,cap=0,max=cap; 7 | cin>>n; 8 | while(n--) 9 | { 10 | cin>>a>>b; 11 | cap=cap-a+b; 12 | if(max 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,a,t; 7 | cin>>n>>t; 8 | while(t--) 9 | { 10 | a=n%10; 11 | switch(a) 12 | { 13 | case 0: 14 | n/=10; 15 | break; 16 | default: 17 | n--; 18 | } 19 | } 20 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main() { 10 | int i, n, t, k, w; 11 | long long sum=0; 12 | 13 | cin>> k>>n>>w; 14 | for(i=1; i<=w; i++){ 15 | sum = sum+(i*k); 16 | } 17 | if(sum<= n){ 18 | cout <<0<<"\n"; 19 | } 20 | else cout << sum - n << "\n"; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Striver CP sheet/implementation-constructive/q16.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int a,b,c=0; 6 | cin>>a>>b; 7 | if(a>b) 8 | c=0; 9 | else 10 | while(a<=b) 11 | { 12 | a=a*3; 13 | b=b*2; 14 | c++; 15 | } 16 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n, k, l, c, d, p, nl, np; 7 | cin >> n >> k >> l >> c >> d >> p >> nl >> np; 8 | int lime = c * d / n; 9 | int drinks = k * l; 10 | int n1 = drinks / (nl * n), n2 = p / (np * n); 11 | int res = (n1 > n2 && lime > n2) ? n2 : ((n1 > lime) ? lime : n1); 12 | cout << res << endl; 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Striver CP sheet/implementation-constructive/q5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int a, b, c; 8 | cin >> a >> b >> c; 9 | a--,b--,c--; 10 | int len = max(a, max(b, c)); 11 | int arr[len]; 12 | int i; 13 | for (i = 0; i < len; i++) 14 | { 15 | arr[i] = (((c - i) >= 0) ? (c - i) : (i - c)) + (((b - i) >= 0) ? (b - i) 16 | : (i - b)) + (((a - i) >= 0) ? (a - i) 17 | : (i - a)); 18 | //cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t,n; 8 | cin>>t; 9 | while(t--) 10 | { 11 | cin>>n; 12 | int tmp=n,c=0,x; 13 | while(tmp!=0){ 14 | x=tmp%10; 15 | if(x!=0) 16 | c++; 17 | tmp/=10; 18 | } 19 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int r,c; 7 | cin>>r>>c; 8 | int i,j; 9 | for(i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,ans=0; 7 | cin>>n; 8 | string str; 9 | while(n--) 10 | { 11 | cin>>str; 12 | switch(str[0]) 13 | { 14 | case 'T':ans+=4;break; 15 | case 'C':ans+=6;break; 16 | case 'I':ans+=20;break; 17 | case 'O':ans+=8;break; 18 | case 'D':ans+=12;break; 19 | default:break; 20 | } 21 | } 22 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | int i,arr[n]; 8 | for(i=0;i>arr[i]; 10 | int min=0,max=0; 11 | for(i=1;i=arr[i]) 14 | min=i; 15 | if(arr[max]min) 20 | res--; 21 | cout<