├── AtCoder ├── ABC 170 │ ├── A.py │ ├── B.py │ ├── C.py │ ├── D.py │ └── README.md ├── ABC171 │ ├── A.py │ ├── B.py │ ├── C.cpp │ ├── D.py │ └── E.py ├── contest 160 │ ├── Rgapple.py │ ├── Travelling.py │ ├── coffee.py │ └── golden.py ├── contest 163 │ ├── A.py │ ├── B.py │ ├── C.cpp │ ├── D.cpp │ └── E.py ├── contest 164 │ ├── A.py │ ├── B.py │ ├── C.py │ └── D.py └── contest 169 │ ├── A.py │ ├── B.py │ ├── C.py │ ├── D.py │ └── E.py ├── Camp-Summer-Training ├── Readme.md └── week1 │ ├── 1 │ └── week1_1.py │ ├── 2 │ ├── test2.py │ └── week1_2.py │ ├── 4 │ ├── testing.py │ └── week1_4.py │ └── 5 │ ├── testing.py │ └── week1_5.py ├── Code Jam └── 2020 │ ├── A.py │ ├── B.py │ └── C.py ├── CodeChef ├── Contest │ ├── Aarambh2020 │ │ ├── Jolites.c │ │ ├── Straight_Lines.c │ │ └── Xor_Segment.py │ ├── Beautiful_Vies_Magnificent_Desolation.py │ ├── Breaking_Bricks.c │ ├── Constant_series.c │ ├── Cypher Ball │ │ └── LPC_Number.cpp │ ├── Discrepancies_in_the_Voters_List.py │ ├── For_The_Benefit_Of_All.c │ ├── Honour Code 2019 │ │ └── Pass_XOR_Fail.py │ ├── January_Lunchtime │ │ └── Chef_And_StreetFood.py │ ├── June Long │ │ ├── Readme.md │ │ ├── chficrm.py │ │ ├── eoeo.py │ │ ├── evenmatrix.py │ │ ├── pricecon.py │ │ └── xystr.py │ ├── Keteki Quickmatch-1 │ │ └── DJ_Party.py │ ├── List_Of_Books.py │ ├── Longest_Palindromic_Substring.c │ ├── March CookOff 2020 │ │ └── Find_Your_Gift.py │ ├── Reverse.py │ ├── Sahil_Loves_Good_Scorer.c │ ├── SegmentTree_MaxRangeQuery.cpp │ ├── That_Is_My_Score.c │ ├── The_Operations.c │ ├── Zero_One_Tiles.py │ ├── ascii_to_char.py │ └── dynamo.py ├── Easy │ ├── A_Very_Easy_Problem.py │ ├── Arranging_Cup_Cakes.c │ ├── Bear_And_Extra_Number.py │ ├── Caravans.cpp │ ├── Carvans.c │ ├── Chef_And_Easy_Problem.py │ ├── Chef_And_Feedback.c │ ├── Chef_And_Notebooks.py │ ├── Chef_Jumping.py │ ├── Count_Substrings.c │ ├── Counting_Pretty_Numbers.c │ ├── Disperancies_In_Voters_List.py │ ├── Dividing_Sums.c │ ├── Factorial.c │ ├── FindMatches.c │ ├── Jewels_And_Stones.py │ ├── Lapindromes.py │ ├── Life_Universe_And_Everything.cpp │ ├── Life_Universe_And_Everything.py │ ├── Matches.c │ ├── Maximum_Weight_Difference.py │ ├── Prime_Generator.c │ ├── Racing_Horses.py │ ├── Reverse_integer.cpp │ └── Uncle_Johny.py ├── Medium │ ├── Coin_Flip.cpp │ ├── Laddu.py │ ├── Smart_Phone.cpp │ └── Trailing_zeroes.cpp ├── beginner │ ├── ATM │ ├── ATM2_C │ ├── Addition.py │ ├── AreaOrPerimeter_C │ ├── Buggy_Calculator.c │ ├── Buying_New_Tablet.py │ ├── ChefAndCookOff_C │ ├── ChefAndDigitsOfANumber_Python │ ├── ChefAndDolls │ ├── ChefAndSnackDown_C │ ├── ChefAndTableTennis_Python │ ├── Chef_And_Coloring.py │ ├── Chef_And_Eid.py │ ├── Chef_And_Fruits.c │ ├── Chef_And_Remissness.c │ ├── Coins_and_Triangles.c │ ├── Cutting_Recipes.c │ ├── DecrementOrIncrement_C │ ├── Discount_Shop.py │ ├── Farmer_Feb.c │ ├── Find_The_Maximum_Value.py │ ├── From_Heaven_To_Earth.py │ ├── GCDandLCM_C │ ├── Good_Joke.c │ ├── GradeTheSteel │ ├── Help_Lost_Robot.c │ ├── MalavikaAndBalloons_C │ ├── Mutated_Minions.c │ ├── NoOfDigits_C │ ├── PackagingCupcakes.c │ ├── ProgramYourOwnCalculator_C │ ├── Puppy_And_Sum.c │ ├── Rectangle_C │ ├── Roots_Of_Quadratic_Equations.py │ ├── Smallest_No_Of_Notes.c │ ├── StudyingAlphabet_Python │ ├── SumOrDifference_C │ ├── Tanu_And_HeadBob.py │ ├── TheLeadGame_Python │ ├── The_Smallest_Pair.c │ ├── Three_Way_Communication.py │ ├── TwoVsTen_C │ ├── VowelOrConsonant │ └── cops_and_thief_devu.c └── peer │ ├── Matryoshka_Dolls.py │ ├── Minimizing_The_Dot_Product.py │ └── The_Saviours.cpp ├── Geeks4Geeks ├── Array │ ├── Balanced_Array.cpp │ ├── Binary_Search.cpp │ ├── Find_Min_Max.cpp │ ├── Find_Min_Secmin.cpp │ ├── First_And_Last_Occurance.cpp │ ├── Game_With_NOs.cpp │ ├── Immediate_Smaller_Element.cpp │ ├── Ishaan_Loves_Chocolates.cpp │ ├── Kth_Smallest.cpp │ ├── Learn_To_Comment.cpp │ ├── Linear_Search.cpp │ ├── Majority_Element_notopt.cpp │ ├── Minimum_Distance.cpp │ ├── Missing_Number_In_Array.cpp │ ├── Multiply_LeftRight_Subarray.cpp │ ├── Play_With_OR.cpp │ ├── Product_Of_Array_Elements.cpp │ ├── Pythagorean_Triplets(not opt).cpp │ ├── Rotating_An_Array.cpp │ ├── Rotating_An_Array.py │ ├── Searching_number.cpp │ ├── Second_Largest_Element.cpp │ ├── Stuffs_Division.cpp │ ├── Sum_Of_Array.cpp │ ├── Sum_Of_f(a[i],a[j]).cpp │ ├── Two_Arrays_AreEqual.cpp │ ├── XOR_Of_A_Given_Range.cpp │ └── kth_smallest_quickselect.cpp ├── BST │ ├── Insert_Node_In_BST.cpp │ ├── Minimum_Element_In_BST.cpp │ ├── Search_Element_In_BST.cpp │ └── Sum_Of_Leaf_Nodes.cpp ├── Binary Trees │ ├── Count_Leaves.cpp │ ├── Count_Non_Leafnodes.cpp │ ├── Height.cpp │ ├── Inorder.cpp │ ├── Preorder.cpp │ ├── Size.cpp │ ├── Sum_Leaf.cpp │ └── Sum_Of_Binary_Tree.cpp ├── Hashing │ └── Majority_Element.cpp ├── Heap │ ├── Adding_Array_elements.cpp │ ├── Height_Of_Heap.cpp │ ├── Kth_Largest_Element.cpp │ └── Kth_Smallest_Element.cpp ├── Misc │ ├── Replace_0_with_5.cpp │ └── Rotate_Array.py └── Stacks │ ├── 1.cpp │ ├── Get_Min_At_Pop.cpp │ ├── Maximum_Rectangle,cpp │ ├── Maximum_Rectangle.py │ ├── Pairwise_Consecutive_Elements.cpp │ ├── Remove_Repeated_Digits.py │ ├── Reverse_A_String.cpp │ ├── Stack_Designer.cpp │ ├── Stack_Using_Array.c │ ├── Stock_Span.cpp │ └── balanced_Paranthesis.cpp ├── HackerEarth ├── Algorithms │ ├── Binary_Search │ │ └── Bishu_And_Soldiers.c │ ├── Bubble Sort │ │ ├── Easy_Going.py │ │ ├── Save_Patients.c │ │ └── Shubam_And_XOR.py │ ├── Insertion Sort │ │ └── The_Rise_Of_Wierd_Things.py │ ├── Linear_Search │ │ ├── Min-Max.py │ │ ├── Monk_Takes_A_Walk.py │ │ ├── Simple_Search.c │ │ └── Square_Transaction.c │ ├── Merge Sort │ │ ├── Chandu_And_GF_Returns.c │ │ └── Puchi_And_Luggage.cpp │ └── Selection Sort │ │ └── Selection_Sort_Practice.c ├── Array1D │ ├── Achhe_Din.py │ ├── Anshul_Usama_And_Punishment.py │ ├── Array_Game.py │ ├── Binary_Queries.c │ ├── DedicationLevel.py │ ├── Hamiltonian_And_Lagrangian.c │ ├── Help_Jarvis.py │ ├── LAL_Evaluation.c │ ├── Long_ATM_Queue.py │ ├── MarkTheAnswer.py │ ├── Maximize_The_Earning.c │ ├── Maximum_Of_K_Size_Subarrays.py │ ├── Micro_And_Array_Update.c │ ├── Monk_And_Lucky_Minimum.py │ ├── Monk_And_Power_Of_Time.c │ ├── Monk_And_Welcome_Problem.c │ ├── Most_Frequent.py │ ├── Neutalisation_of_charges.py │ ├── Pepper_And_Contiguous_Even_Subarray.py │ ├── Prasun_The_Detective.py │ ├── R-r-riddikulus.py │ ├── Reverse_An_Array.c │ ├── Sumit's_Love_For_Mathematics.c │ └── Takeoff.c ├── Basics │ ├── Bit Manipulation │ │ └── The_Castle_Gate.cpp │ ├── Find_Product.c │ ├── IO │ │ ├── Ali_And_People.py │ │ ├── Aman_And_Sharma.cpp │ │ ├── Arithmetic_Progression.py │ │ ├── Book_Of_Potion_Making.py │ │ ├── Bricks_Game.cpp │ │ ├── Char_Sum.cpp │ │ ├── Cost_Of_Balloons.cpp │ │ ├── Count_Divisors.cpp │ │ ├── Divisibility.py │ │ ├── Doctors_Secret.cpp │ │ ├── Duration.py │ │ ├── E_Maze.py │ │ ├── Factorial!.cpp │ │ ├── Goki_And_Breakup.java │ │ ├── Hello.java │ │ ├── I_am_Easy.cpp │ │ ├── Ladderophilia.py │ │ ├── Print_The_Number.cpp │ │ ├── Roy_And_Profilepic.cpp │ │ ├── Seating_Arrangement.cpp │ │ ├── Teddy_And_Tweety.java │ │ ├── Two_Strings.py │ │ └── life_and_everthing.java │ ├── Palindromic_String.py │ ├── Prime_Number.c │ └── Zoos.py ├── Binary Search Trees │ ├── Distinct_Count.py │ ├── Monk_And_CursedTree.py │ ├── Monk_And_His_Friends.py │ ├── Monk_Watching_Fight.py │ └── Yatin_Plays_Pubg.py ├── Contests │ └── Codathon-MANIT │ │ ├── Day1.py │ │ └── Day2.c ├── Graphs │ ├── Bishu_And_Girlfriend.py │ ├── Gas_Stations.py │ ├── Graphs.py │ ├── Monk_And_Islands.py │ ├── Monk_Real_Estate.py │ └── flight_plan.py ├── Greedy Algorithms │ ├── Coprimes.py │ └── ExploringRuins.py ├── Hashing │ ├── Alien_Language.py │ ├── All_Vowels.py │ ├── Bob_And_String.py │ ├── Frequency_Of_Students.py │ ├── Jhool_And_Magical_Jewels.py │ ├── KK_crush.py │ ├── Maximum_Occurance.py │ ├── Monk_And_Kundan.py │ ├── N_Coordinates.py │ ├── N_Coordinates_Pair.py │ ├── Pair_Sums.py │ ├── Xsquare_And_Doublestrings.py │ └── Xsquare_And_Palindrome_Insertion.py ├── Multi Dimensional Arrays │ ├── Alternate_Elements.py │ └── Transpose.py ├── Polygon_Possible.py ├── Python │ ├── 13_Reasons_Why.py │ ├── Jadoo_And_DNA.py │ ├── Jadoo_Hates_Numbers.py │ └── Jadoo_Vs_Koba.py ├── Save_Mrinal.py ├── Segment Trees │ ├── Zeros_And_Ones.c │ └── Zeros_And_Ones.cpp ├── SnackDown_Contest.py ├── Speed.c ├── Stacks │ └── Balanced_Brackets.cpp └── Strange_Game.py ├── LICENSE ├── LeetCode ├── Backspace Strings │ └── Backspace_String_Compare.cpp ├── Binary Tree Inorder │ └── Inorder_Traversal.cpp ├── Buy And Sell Stock2 │ └── Buy_And_Sell_Stock2.cpp ├── Container With Most Water │ └── Container_With_Most_Water.cpp ├── Contiguous subarray │ └── Contiguous_Subarray.py ├── Counting Elements │ └── Counting_Elements.py ├── Diameter BT │ └── DiameterOfBinaryTree.py ├── Even Digits │ └── Even_Digits.py ├── Group Anagrams │ └── Group_Anagrams.py ├── Happy Number │ └── Happy_Number.cpp ├── Jewels And Stones │ └── Jewels_And_Stones.py ├── KeyBoard Row │ └── Keyboard_Row.py ├── Largest Sum Subarray │ └── Largest_Sum_Subarray.cpp ├── Largest_Rectangle │ └── Largest_Rectangle.cpp ├── Last Stone Weight │ └── Last_Stone_Weight.cpp ├── Linked List Middle │ └── Middle_Of_Linked_List.cpp ├── Maximum Balloons │ └── Maximum_Number_Of_Balloons.py ├── Maximum Depth │ └── Maximum_Depth.cpp ├── Min Stack │ └── Min_Stack.cpp ├── Move Zeroes │ └── Move_Zeroes.cpp ├── N Repeated Elements │ └── N_Repeated_Elements ├── Palindrome_Number │ ├── Palindrome_Number.py │ └── Palindrome_nummber.cpp ├── Preorder Traversal │ └── Preoreder_Traversal.cpp ├── Product and Sum │ └── Subtract_Product_And_Sum.py ├── Reverse Linked List │ ├── Reverse_LL.cpp │ └── Reverse_Linkedlist.c ├── Reverse_Integer │ └── Reverse_integer.py ├── Reverse_Stringarray │ ├── Reverse_String.py │ └── Reverse_Stringarray.cpp ├── Running_Sum_1d │ └── Running_Sum.py ├── Same Tree │ └── Same_Tree.cpp ├── Shuffle The array │ └── Array_Shuffle.py ├── Single_Number │ └── Single_Number.cpp ├── String Shifts │ └── Perform_String_Shifts.py ├── Symmetric Tree │ └── Symmetric_Tree.cpp ├── Unique Number Of Occurances │ └── Unique_Occurances.py └── Valid_Paranthesis │ └── Valid_Paranthesis.cpp ├── README.md ├── Resources └── Readme.md ├── SPOJ ├── Adding_Reversed_Number.cpp ├── Candy1.cpp ├── Factorial.cpp ├── Feynman.c ├── Small_Factorial.py ├── What's_Next.py ├── bugs_life.cpp ├── fashion.py ├── life_and_everthing.cpp ├── prime1.cpp ├── prime1.py └── rectangles.c ├── Snippets ├── DSA_PROBLEMS │ ├── Linked_List │ │ ├── delete_linked_list.c │ │ ├── linked_list1.c │ │ ├── linked_list_insert.c │ │ └── linked_list_search.c │ ├── Optimized_Naive_String_Matching.c │ ├── String_Mapping_using_Rollinghash.c │ ├── String_Matching1.c │ ├── add_2_big_numbers.c │ ├── add_2_numbers_linked_list.c │ ├── add_two_n_bit_integers.c │ ├── binarystringmatching.c │ ├── factorial_of_big_number.c │ ├── hashtable.c │ ├── multiply_2_big_integers.c │ └── rabinkarp.c ├── Search │ └── linearsearch.c ├── Sieve of Erathosthens │ └── Sieve.cpp ├── Sorting │ ├── Big Sort │ ├── Bubble_Sort.c │ ├── Bubble_Sort.py │ ├── Insertion_Sort │ ├── Quick Sort │ ├── insertionsort.c │ ├── insertionsort.py │ └── mergeSort.c └── String Functions │ ├── Strcpy │ └── strcat_C ├── Templates ├── Python │ └── template.py ├── cpp │ ├── template1.cpp │ └── template2.cpp └── java │ └── Main.java ├── UVa └── ad-hoc │ ├── 100-The_3n+1_problem.cpp │ ├── 10082-WERTYU.py │ ├── 10420-ListofConquests.py │ ├── 10683-TheDecadaryWatch.py │ ├── 10812-BeatTheSpread.py │ ├── 10921-FindTheTelephone.py │ ├── 11044-SearchingForNessy.py │ ├── 11340-Newspaper.py │ ├── 11498-DivisionOfNlogonia.py │ ├── 11547-AutomaticAnswer.py │ ├── 11727-CostCutting.py │ ├── 272-TEX_Quotes.py │ ├── 483-Word_Scramble.py │ ├── 573-TheSnail.py │ ├── 661-BlowingFuses.py │ └── 941-Permutations.py └── hackerrank ├── 30 Days of Code ├── Day0.py ├── Day14.py ├── Day16.py ├── Day18.py ├── Day19.py ├── Day20.py ├── Day25.py ├── Day28.py ├── Day29.py ├── Day4.py ├── Day6.py └── Day8.py ├── Data Structures ├── Arrays-DS.py ├── Data Structures │ └── Arrays.cpp ├── Stacks │ ├── Balanced_Brackets.cpp │ ├── Equal_Stacks.c │ ├── Equal_Stacks.cpp │ ├── Equal_Stacks.py │ ├── Game_Of_Two_Stacks.cpp │ ├── Game_Of_Two_Stacks_Opt.cpp │ ├── Largest_rectangle.cpp │ ├── Maximum_Element.c │ └── Maximum_Element.cpp └── Trees │ ├── Level_Order_Traversal.cpp │ ├── PostOrder.c │ ├── PreOrder.c │ ├── height_of_tree.c │ └── inOrder.c ├── Java Language Proficiency ├── 1DArray.java ├── ArrayList.java ├── IntToString.java ├── Interfaces.java ├── JavaInheritance.java ├── JavaInheritance2.java ├── JavaStringReverse.java ├── Loops.java ├── StdinAndStdout.java ├── StdinAndStdout2.java ├── StringIntro.java ├── Substring.java ├── WelcomeToJava.java ├── abstractClasses.java ├── ifElse.java ├── methodOverride.java ├── subArray.java └── superKeyword.java ├── Project Euler └── #1_CPP ├── Python Language Proficiency ├── Capitalize!.py ├── Counter.py ├── Designer_Door_Mat.py ├── Exceptions.py ├── FindAString_Python ├── Find_Angle_MBC.py ├── Finding_The_Percentage.py ├── Lists.py ├── Merge_The_Tools.py ├── Mutations_Python ├── Sets.py ├── String Split And Join_Python ├── String_Validators.py ├── TextWrap.py ├── Text_Alignment.py ├── The_Minion_Game.py ├── TorsionalAngle.py ├── WordsScore_Python ├── sWAP cASe_python └── stringFormatting.py ├── c language proficiency ├── BitwiseOperator.c ├── BoxesThroughATunnel.c ├── Digit_Frequency.c ├── FunctionsInC_C ├── HelloWorld_C ├── PlayingWithCharecters_C ├── PointersInC_C ├── PrintingNewTokens_C ├── PrintingPattern_C ├── StudentsMarksSum_C ├── SumAndDifferenceOfTwoNumbers_C └── for loop_c ├── c++ language proficiency ├── ArraysIntroduction_CPP ├── ConditionalStatements_CPP ├── ForLoop_CPP ├── Functions_CPP ├── Pointers_CPP ├── Strings_CPP └── data types └── problem_solving ├── 3Dsurfacearea.py ├── Alternating_Characters.c ├── Apples&Oranges.c ├── BetweenTwoSets.py ├── BigSorting.py ├── BirthdayChocalate.c ├── BonAppetit.C ├── BreakingTheRecords.c ├── Camelcase.py ├── ChocalateFest.c ├── Circular_Array_Rotation.py ├── Closest_Number.cpp ├── Counting_Sort1.cpp ├── Counting_Valleys.py ├── Day_Of_The_Programmer.c ├── Divisible_Sum_Pairs.c ├── DrawingBook.py ├── Equalize_The_Array.py ├── FindTheMedian_C ├── Flipping_bits.cpp ├── GameOfThrones1_Python ├── Gradingstudents_C ├── HalloweenSale_C ├── InsertionSort_Part1_C ├── InsertionSort_Part2_C ├── IntroToTutorialChallenges_C ├── Kangaroo_C ├── Lonely_Integer.cpp ├── MIgratoryBirds_Python2 ├── MarsExploration_C ├── Pangrams_Python ├── QuickSort-1_C ├── Running_Time.cpp ├── Service_Lane_C ├── SherlockAndArray_C ├── SockMerchant_Python ├── Solvemefirst_c ├── Sum_Vs_Xor.cpp ├── TaumAndB'day_C ├── absolutePermutation.c++ ├── averybigsum_c ├── birthdaycandles_c ├── comparethetriplets.c ├── containersBalls.cpp ├── corretness&loopinvariant_c ├── debugging_XORstrings.py ├── diagnoldifference.c ├── encryption.cpp ├── first ├── iceCreamParlour.c ├── minimaxsum.c ├── plusminus.c ├── sequenceEquation.py ├── sherlock&squares_c ├── simplearraysum.c ├── sparseArrays.c++ ├── staircase.c ├── timeInWords.cpp └── timeconversion.c /AtCoder/ABC 170/A.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | l = list(map(int,input().split())) 3 | print(l.index(0) + 1) -------------------------------------------------------------------------------- /AtCoder/ABC 170/B.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | x,y = map(int,input().split()) 3 | flag = 0 4 | for i in range(x + 1) : 5 | if i * 4 + (x - i) * 2 == y : 6 | print("Yes") 7 | flag = 1 8 | break 9 | 10 | if flag == 0 : 11 | print("No") -------------------------------------------------------------------------------- /AtCoder/ABC 170/C.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | if __name__ == "__main__": 3 | x,n = map(int,input().split()) 4 | l = list(map(int,input().split())) 5 | if n == 0 : 6 | print(x) 7 | else : 8 | l.sort() 9 | count = 0 10 | dist = 999 11 | ans = -100 12 | for i in range(-100,201) : 13 | if i in l : 14 | continue 15 | if dist > abs(x - i) : 16 | dist = abs(x - i) 17 | ans = i 18 | print(ans) -------------------------------------------------------------------------------- /AtCoder/ABC 170/D.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | l = list(map(int,input().split())) 3 | l.sort() 4 | 5 | count = 0 6 | for i in range(n) : 7 | ok = True 8 | for j in range(i+1,n) : 9 | if l[i]%l[j] == 0 : 10 | ok = False 11 | break 12 | if ok : 13 | count += 1 14 | 15 | if l[n-1] == l[n-2] : 16 | count -= 1 17 | print(count) -------------------------------------------------------------------------------- /AtCoder/ABC 170/README.md: -------------------------------------------------------------------------------- 1 | ABC 170 2 | -------------------------------------------------------------------------------- /AtCoder/ABC171/A.py: -------------------------------------------------------------------------------- 1 | c = str(input()) 2 | if c.isupper(): 3 | print('A') 4 | else: 5 | print('a') 6 | -------------------------------------------------------------------------------- /AtCoder/ABC171/B.py: -------------------------------------------------------------------------------- 1 | l1 = list (map (int, input().strip().split())) 2 | n = l1[0] 3 | k = l1[1] 4 | l = list (map (int, input().strip().split())) 5 | l.sort() 6 | print(sum(l[0:k])) 7 | -------------------------------------------------------------------------------- /AtCoder/ABC171/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX 100001 3 | using namespace std; 4 | 5 | 6 | void printString(long long int n) 7 | { 8 | char str[MAX]; 9 | int i = 0; 10 | 11 | while (n > 0) { 12 | // Find remainder 13 | int rem = n % 26; 14 | 15 | // If remainder is 0, then a 'Z' must be there in output 16 | if (rem == 0) { 17 | str[i++] = 'z'; 18 | n = (n / 26) - 1; 19 | } 20 | else // If remainder is non-zero 21 | { 22 | str[i++] = (rem - 1) + 'a'; 23 | n = n / 26; 24 | } 25 | } 26 | str[i] = '\0'; 27 | 28 | // Reverse the string and print result 29 | reverse(str, str + strlen(str)); 30 | cout << str << endl; 31 | 32 | return; 33 | } 34 | 35 | 36 | int main() 37 | { 38 | long long int n; 39 | cin>>n; 40 | printString(n); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /AtCoder/ABC171/D.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | l = list (map (int, input().strip().split())) 3 | d={} 4 | s = 0 5 | for i in range(n): 6 | s+=l[i] 7 | if l[i] not in d: 8 | d[l[i]] = 1 9 | else: 10 | d[l[i]]+=1 11 | q = int(input()) 12 | for i in range(q): 13 | l2 = list (map (int, input().strip().split())) 14 | b = l2[0] 15 | c = l2[1] 16 | x = 0 17 | y = 0 18 | if b not in d: 19 | x = 0 20 | else: 21 | x = d[b] 22 | if c not in d: 23 | y = 0 24 | else: 25 | y = d[c] 26 | test1 = (c-b)*x 27 | s = s+test1 28 | print(s) 29 | d[b]=0 30 | d[c] = x+y 31 | -------------------------------------------------------------------------------- /AtCoder/ABC171/E.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | a = list (map (int, input().strip().split())) 3 | x = 0 4 | for i in range(n): 5 | x^=a[i] 6 | for i in range(n): 7 | print(a[i]^x,end=" ") 8 | -------------------------------------------------------------------------------- /AtCoder/contest 160/Rgapple.py: -------------------------------------------------------------------------------- 1 | X,Y,A,B,C=(int(x) for x in input().split()) 2 | P=list(map(int, input().split())) 3 | Q=list(map(int, input().split())) 4 | R=list(map(int, input().split())) 5 | 6 | D=sorted(P, reverse=True)[:X] 7 | E=sorted(Q, reverse=True)[:Y] 8 | Z=X+Y 9 | if C>=Z: 10 | F=sorted(R, reverse=True)[:Z] 11 | else: 12 | F=R 13 | 14 | D.extend(E) 15 | D.extend(F) 16 | I=sorted(D, reverse=True)[:Z] 17 | 18 | print(sum(I)) 19 | -------------------------------------------------------------------------------- /AtCoder/contest 160/Travelling.py: -------------------------------------------------------------------------------- 1 | K,N = map(int,input().split()) 2 | A = list(map(int,input().split())) 3 | sub = [abs(A[i] - A[i+1]) for i in range(N-1)] 4 | sub.append(K-A[N-1]+A[0]) 5 | print(K-max(sub)) 6 | -------------------------------------------------------------------------------- /AtCoder/contest 160/coffee.py: -------------------------------------------------------------------------------- 1 | str = input() 2 | n = len(str) 3 | 4 | if(str[2] == str[3] and str[4] == str[5]) : 5 | print("Yes") 6 | else : 7 | print("No") 8 | -------------------------------------------------------------------------------- /AtCoder/contest 160/golden.py: -------------------------------------------------------------------------------- 1 | x = int(input()) 2 | happy = 0 3 | while x >= 500 : 4 | happy += 1000 * int(x/500) 5 | x = x%500 6 | 7 | 8 | while x >= 5 : 9 | happy += 5 * int(x/5) 10 | x = x%5 11 | 12 | 13 | print(happy) 14 | -------------------------------------------------------------------------------- /AtCoder/contest 163/A.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | 4 | r = int(input()) 5 | print(2 *math.pi* r) 6 | 7 | -------------------------------------------------------------------------------- /AtCoder/contest 163/B.py: -------------------------------------------------------------------------------- 1 | n,m = map(int,input().split()) 2 | assign = list(map(int,input().split())) 3 | work = sum(assign) 4 | if n - work >= 0 : 5 | print(n - work) 6 | else : 7 | print("-1") 8 | -------------------------------------------------------------------------------- /AtCoder/contest 163/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long 4 | 5 | 6 | 7 | int main() 8 | { 9 | ll n; 10 | cin >> n; 11 | ll arr[n - 1]; 12 | for(ll i = 0;i < n - 1;i++) cin >> arr[i]; 13 | ll boss[n + 1]; 14 | for(ll i = 0;i < n + 1;i++) 15 | { 16 | boss[i] = 0; 17 | } 18 | for(ll i = 0;i < n - 1;i++) 19 | { 20 | boss[arr[i]] += 1; 21 | } 22 | for(ll i = 1;i < n + 1;i++) 23 | { 24 | cout << boss[i] << endl; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /AtCoder/contest 163/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long 4 | constexpr int MOD = 1e9 + 7; 5 | 6 | 7 | ll progsum(ll a,ll d,ll n) 8 | { 9 | return n * (2 * a + (n - 1) * d)/2; 10 | } 11 | 12 | 13 | int main() 14 | { 15 | ll n,k; 16 | cin >> n >> k; 17 | ll r = 0; 18 | ll i = 0; 19 | for(i = k;i <= n + 1;i++) 20 | { 21 | ll series_min = progsum(0,1,i); 22 | ll series_max = progsum(n,-1,i); 23 | r += series_max - series_min + 1; 24 | r = r%MOD; 25 | } 26 | cout << r << endl; 27 | } 28 | -------------------------------------------------------------------------------- /AtCoder/contest 163/E.py: -------------------------------------------------------------------------------- 1 | def searchend(arr,x) : 2 | i = len(arr) - 1 3 | while(i >= 0) : 4 | if arr[i] == x : 5 | break 6 | i -= 1 7 | return i 8 | 9 | 10 | def searchbeg(arr,x) : 11 | i = 0 12 | while(i < len(arr)) : 13 | if arr[i] == x : 14 | break; 15 | i += 1 16 | return i 17 | 18 | 19 | 20 | 21 | 22 | n = int(input()) 23 | l = list(map(int,input().split())) 24 | x = l[:] 25 | l.sort() 26 | happy = 0 27 | while(len(l) > 1) : 28 | a = searchbeg(x,l[0]) 29 | b = searchend(x,l[-1]) 30 | happy += l[0] * abs(a - b) 31 | happy += l[-1] * abs(a - b) 32 | l.pop(0) 33 | l.pop(-1) 34 | if (a > b) : 35 | x.pop(a) 36 | x.pop(b) 37 | else : 38 | x.pop(b) 39 | x.pop(a) 40 | print(happy) 41 | #print(l) 42 | #print(x) 43 | -------------------------------------------------------------------------------- /AtCoder/contest 164/A.py: -------------------------------------------------------------------------------- 1 | sheep,wolf = map(int,input().split()) 2 | 3 | if sheep > wolf : 4 | print("safe") 5 | else : 6 | print("unsafe") 7 | -------------------------------------------------------------------------------- /AtCoder/contest 164/B.py: -------------------------------------------------------------------------------- 1 | a,b,c,d = map(int,input().split()) 2 | 3 | while a > 0 and c > 0 : 4 | c -= b 5 | if c <= 0 : 6 | break 7 | a = a - d 8 | 9 | if a <= 0 : 10 | print("No") 11 | elif c <= 0: 12 | print("Yes") 13 | -------------------------------------------------------------------------------- /AtCoder/contest 164/C.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | l = [] 3 | while n > 0 : 4 | l.append(input()) 5 | n -= 1 6 | 7 | uniq = set(l) 8 | print(len(uniq)) 9 | -------------------------------------------------------------------------------- /AtCoder/contest 164/D.py: -------------------------------------------------------------------------------- 1 | S=list(input()) 2 | S.reverse() 3 | N=len(S) 4 | R=[0]*N 5 | R10=[0]*N 6 | m=2019 7 | K=0 8 | 9 | R10[0]=1 10 | R[0]=int(S[0])%m 11 | for i in range(1,N): 12 | R10[i]=(R10[i-1]*10)%m 13 | R[i]=(R[i-1]+int(S[i])*R10[i])%m 14 | d={} 15 | for i in range(2019): 16 | d[i]=0 17 | 18 | for i in range(N): 19 | d[R[i]]+=1 20 | ans=0 21 | for i in range(2019): 22 | if i == 0: 23 | ans += d[i] 24 | ans +=d[i]*(d[i]-1)//2 25 | else: 26 | ans +=d[i]*(d[i]-1)//2 27 | print(ans) 28 | -------------------------------------------------------------------------------- /AtCoder/contest 169/A.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | 3 | 4 | if __name__ == "__main__": 5 | a,b = map(int,input().split()) 6 | print(a*b) 7 | -------------------------------------------------------------------------------- /AtCoder/contest 169/B.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | import math 3 | 4 | 5 | if __name__ == "__main__": 6 | n = int(input()) 7 | l = list(map(int,input().split())) 8 | if 0 in l : 9 | print("0") 10 | else : 11 | flag = 1 12 | prod = 1 13 | for i in range(n) : 14 | prod = prod * l[i] 15 | if prod > int(math.pow(10,18)) : 16 | flag = 0 17 | break 18 | if flag == 0 : 19 | print("-1") 20 | else : 21 | print(prod) 22 | -------------------------------------------------------------------------------- /AtCoder/contest 169/C.py: -------------------------------------------------------------------------------- 1 | import math 2 | from decimal import Decimal, getcontext 3 | 4 | 5 | A, B = input().split() 6 | print(math.floor(Decimal(A) * Decimal(B))) 7 | -------------------------------------------------------------------------------- /AtCoder/contest 169/E.py: -------------------------------------------------------------------------------- 1 | import itertools 2 | 3 | N = int(input()) 4 | AB = [list(map(int ,input().split())) for _ in range(N)] 5 | 6 | p = itertools.permutations(AB,N) 7 | ans = 0 8 | s = set() 9 | 10 | for v in p: 11 | if N % 2 != 0: 12 | m = list(p)[int(N+1/2-1)] 13 | if m not in s: 14 | ans += 1 15 | s.add(m) 16 | else: 17 | k = list(p)[N/2-1] 18 | l = list(p)[N/2] 19 | print(ans) 20 | -------------------------------------------------------------------------------- /Camp-Summer-Training/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | ## Week 1 3 |
    4 |
  1. codeforces.com/contest/469/problem/A
  2. 5 |
  3. codeforces.com/contest/460/problem/A
  4. 6 |
  5. 7 |
  6. codeforces.com/contest/318/problem/A
  7. 8 |
  8. codeforces.com/contest/25/problem/A
  9. 9 |
10 | -------------------------------------------------------------------------------- /Camp-Summer-Training/week1/1/week1_1.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | import numpy as np 3 | import datetime as dt 4 | 5 | 6 | begin_time = dt.datetime.now() 7 | lvls = int(input()) 8 | x = list(map(int,input().split())) 9 | y = list(map(int,input().split())) 10 | x = x[1:] 11 | y = y[1:] 12 | flag = 1 13 | 14 | for i in range(1,lvls + 1) : 15 | if i not in x and i not in y : 16 | flag = 0 17 | break 18 | else : 19 | continue 20 | 21 | 22 | if flag == 1 : 23 | print("I become the guy.") 24 | else : 25 | print("Oh, my keyboard!") 26 | 27 | 28 | execution_time = dt.datetime.now() - begin_time 29 | print(execution_time) 30 | -------------------------------------------------------------------------------- /Camp-Summer-Training/week1/2/week1_2.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | 3 | def sock_days(n,m) : 4 | if n == m : 5 | return n + 1 6 | elif m > n : 7 | return n 8 | else : 9 | x = n 10 | rem = n//m 11 | count = 0 12 | while (x - m + 1 > 0) : 13 | count += 1 14 | x = x - m + 1 15 | return n + count 16 | 17 | 18 | 19 | if __name__ == "__main__": 20 | n,m = map(int,input().split()) 21 | days = sock_days(n,m) 22 | print(days) -------------------------------------------------------------------------------- /Camp-Summer-Training/week1/4/testing.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from week1_4 import number 3 | 4 | class TestSum(unittest.TestCase) : 5 | def testcase1(self) : 6 | n = 10 7 | pos = 3 8 | result = number(n,pos) 9 | self.assertEqual(result,5) 10 | 11 | def testcase2(self) : 12 | n = 7 13 | pos = 7 14 | result = number(n,pos) 15 | self.assertEqual(result,6) 16 | 17 | def testcase3(self) : 18 | n = 8 19 | pos = 8 20 | result = number(n,pos) 21 | self.assertEqual(result,8) 22 | 23 | 24 | 25 | 26 | if __name__ == "__main__": 27 | unittest.main() 28 | -------------------------------------------------------------------------------- /Camp-Summer-Training/week1/4/week1_4.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | import math 3 | import numpy 4 | 5 | 6 | def number(n,pos) : 7 | if pos <= math.ceil(n/2) : 8 | #odd 9 | num = 1 + (pos - 1)*2 10 | else : 11 | #even 12 | num = 2 + (pos - math.ceil(n/2) - 1)*2 13 | return num 14 | 15 | 16 | 17 | if __name__ == "__main__": 18 | n,pos = map(int,input().split()) 19 | num = number(n,pos) 20 | print(num) 21 | -------------------------------------------------------------------------------- /Camp-Summer-Training/week1/5/testing.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from week1_5 import evenness 3 | 4 | class TestSum(unittest.TestCase) : 5 | def testcase1(self) : 6 | n = 5 7 | l = [2,4,7,8,10] 8 | result = evenness(l,n) 9 | self.assertEqual(result,3) 10 | 11 | def testcase2(self) : 12 | n = 4 13 | l = [1,2,1,1] 14 | result = evenness(l,n) 15 | self.assertEqual(result,2) 16 | 17 | """ 18 | def testcase3(self) : 19 | n = 8 20 | pos = 8 21 | result = number(n,pos) 22 | self.assertEqual(result,8) 23 | """ 24 | 25 | 26 | 27 | if __name__ == "__main__": 28 | unittest.main() -------------------------------------------------------------------------------- /Camp-Summer-Training/week1/5/week1_5.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | import math 3 | import numpy 4 | 5 | def evenness(l,n) : 6 | x,y = 0,0 7 | count_even = 0 8 | count_odd = 0 9 | for i in range(n) : 10 | if l[i]%2 == 0 : 11 | count_even += 1 12 | x = i 13 | else : 14 | count_odd += 1 15 | y = i 16 | if count_odd == 1 : 17 | return y + 1 18 | else : 19 | return x + 1 20 | 21 | 22 | if __name__ == "__main__": 23 | n = int(input()) 24 | l = list(map(int,input().split())) 25 | pos = evenness(l,n) 26 | print(pos) 27 | -------------------------------------------------------------------------------- /Code Jam/2020/A.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | test = int(input()) 4 | for i in range(1, test + 1): 5 | n = int(input()) 6 | arr = []; 7 | rows = 0; 8 | columns = 0; 9 | for j in range(1, n + 1): 10 | tmp = [int(s) for s in input().split(" ")] 11 | if len(tmp) != len(set(tmp)): 12 | rows += 1; 13 | arr.append(tmp) 14 | matrix = np.array(arr); 15 | trace = matrix.diagonal().sum(); 16 | transpose = matrix.transpose(); 17 | for j in range(0, n): 18 | if len(transpose[j]) != len(set(transpose[j])): 19 | columns += 1; 20 | print("Case #{}: {} {} {}".format(i, trace, rows, columns)) 21 | -------------------------------------------------------------------------------- /CodeChef/Contest/Aarambh2020/Jolites.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | int main() 7 | { 8 | int test; 9 | scanf("%d",&test); 10 | char ptn[] = "JGEC"; 11 | while(test > 0) 12 | { 13 | int n; 14 | int count = 0; 15 | scanf("%d",&n); 16 | int i = 0,j = 0; 17 | char txt[n]; 18 | scanf("%s",txt); 19 | for(i = 0;i < n - 4 + 1;i++) 20 | { 21 | for(j = 0;j < 4;j++) 22 | { 23 | if(txt[i + j] != ptn[j]) 24 | { 25 | break; 26 | } 27 | } 28 | if(j == 4) 29 | { 30 | count ++; 31 | } 32 | } 33 | printf("%d\n",count); 34 | test --; 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /CodeChef/Contest/Aarambh2020/Straight_Lines.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int test; 8 | scanf("%d",&test); 9 | while (test > 0) 10 | { 11 | int n; 12 | scanf("%d",&n); 13 | int pt[n][2]; 14 | int count = 0; 15 | for(int i = 0;i < n;i++) 16 | { 17 | scanf("%d%d",&pt[i][0],&pt[i][1]); 18 | } 19 | for(int i = 0;i < n - 1;i++) 20 | { 21 | for(int j = i + 1;j < n;j++) 22 | { 23 | if(pt[i][0] != pt[j][0] && pt[i][1] != pt[j][1]) 24 | { 25 | count ++; 26 | } 27 | } 28 | } 29 | printf("%d\n",count); 30 | test --; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /CodeChef/Contest/Beautiful_Vies_Magnificent_Desolation.py: -------------------------------------------------------------------------------- 1 | # cook your code here 2 | t = int(raw_input()) 3 | for k in range(t): 4 | arr = map(int, raw_input().split()) 5 | n=arr[0] 6 | d=arr[1] 7 | l=[] 8 | max = 0 9 | for i in range(n): 10 | name = str(raw_input()) 11 | l.append(name) 12 | i=0 13 | while(i<=n-d): 14 | if(len(set(l[i:i+d]))>max): 15 | max = len(set(l[i:i+d])) 16 | i+=1 17 | print(max) 18 | -------------------------------------------------------------------------------- /CodeChef/Contest/Discrepancies_in_the_Voters_List.py: -------------------------------------------------------------------------------- 1 | n1,n2,n3 = raw_input("").split(" ") 2 | n1 = int(n1) 3 | n2 = int(n2) 4 | n3 = int(n3) 5 | sum = n1 + n2 + n3 6 | l = [] 7 | for i in range(sum) : 8 | a = input("") 9 | l.append(a) 10 | result_list = [] 11 | for i in l : 12 | count = l.count(i) 13 | if count > 1 : 14 | result_list.append(i) 15 | 16 | result_list = list(dict.fromkeys(result_list)) 17 | print len(result_list) 18 | result_list.sort() 19 | for i in result_list : 20 | print i 21 | -------------------------------------------------------------------------------- /CodeChef/Contest/For_The_Benefit_Of_All.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int test; 7 | scanf("%d",&test); 8 | while(test > 0) 9 | { 10 | int n; 11 | int count = 0; 12 | scanf("%d",&n); 13 | double arr[n]; 14 | for(int i = 0;i < n;i++) 15 | { 16 | scanf("%lf",&arr[i]); 17 | } 18 | for(int i = 0;i < n;i++) 19 | { 20 | for(int j = i + 1;j < n;j++) 21 | { 22 | if(arr[i] >= arr[j]/2.0 && arr[j] >= arr[i]/2.0) 23 | { 24 | count ++; 25 | } 26 | } 27 | } 28 | printf("%d\n",count); 29 | test --; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /CodeChef/Contest/Honour Code 2019/Pass_XOR_Fail.py: -------------------------------------------------------------------------------- 1 | def computeXOR(n) : 2 | switch = { 3 | 0 : n, 4 | 1 : 1, 5 | 2: n + 1, 6 | 3 : 0, 7 | } 8 | return switch.get( n & 3, "") 9 | 10 | 11 | l = 0 12 | r = int(input()) 13 | print(computeXOR(r) ^ computeXOR(l - 1)) 14 | 15 | #for hacktober fest 16 | -------------------------------------------------------------------------------- /CodeChef/Contest/January_Lunchtime/Chef_And_StreetFood.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | test = int(input()) 3 | while test > 0 : 4 | n = int(input()) 5 | l2 = [] 6 | for i in range(n) : 7 | l1 = list(map(int,input().split())) 8 | l2.append((l1[1]//(l1[0] + 1)) * l1[2]) 9 | print(max(l2)) 10 | test -= 1 11 | -------------------------------------------------------------------------------- /CodeChef/Contest/June Long/Readme.md: -------------------------------------------------------------------------------- 1 | June Long challenge 2 | -------------------------------------------------------------------------------- /CodeChef/Contest/June Long/eoeo.py: -------------------------------------------------------------------------------- 1 | def recur(num) : 2 | while num >= 1 : 3 | if num%2 == 0 : 4 | return recur(num//2) 5 | else : 6 | return num 7 | 8 | 9 | def solve(tom) : 10 | if tom%2 != 0 : 11 | print(tom//2) 12 | if tom%2 == 0 : 13 | number = recur(tom) 14 | print(number//2) 15 | 16 | 17 | 18 | 19 | 20 | test = int(input()) 21 | while test > 0 : 22 | ts = int(input()) 23 | solve(ts) 24 | test -= 1 -------------------------------------------------------------------------------- /CodeChef/Contest/June Long/evenmatrix.py: -------------------------------------------------------------------------------- 1 | test = int(input()) 2 | while test > 0 : 3 | n = int(input()) 4 | l = [] 5 | flag = 0 6 | for i in range(n) : 7 | for j in range(n*i + 1,(n*i) + n + 1) : 8 | l.append(j) 9 | if flag == 0 : 10 | print(*l,sep = " ") 11 | l.clear() 12 | flag = 1 13 | else : 14 | l.reverse() 15 | print(*l,sep = " ") 16 | l.clear() 17 | flag = 0 18 | test -= 1 -------------------------------------------------------------------------------- /CodeChef/Contest/June Long/pricecon.py: -------------------------------------------------------------------------------- 1 | test = int(input()) 2 | while test > 0 : 3 | n,k = map(int,input().split()) 4 | p = list(map(int,input().split())) 5 | original = 0 6 | later = 0 7 | for i in p : 8 | if i > k : 9 | later += k 10 | original += i 11 | else : 12 | later += i 13 | original += i 14 | print(original-later) 15 | test -= 1 -------------------------------------------------------------------------------- /CodeChef/Contest/June Long/xystr.py: -------------------------------------------------------------------------------- 1 | test = int(input()) 2 | while test > 0 : 3 | string = input() 4 | count = 0 5 | i = 0 6 | n = len(string) 7 | while i < n - 1: 8 | if string[i] == 'x' and string[i + 1] == 'y' : 9 | count += 1 10 | i += 2 11 | elif string[i] == 'y' and string[i + 1] == 'x' : 12 | count += 1 13 | i += 2 14 | else : 15 | i += 1 16 | print(count) 17 | test -= 1 -------------------------------------------------------------------------------- /CodeChef/Contest/Keteki Quickmatch-1/DJ_Party.py: -------------------------------------------------------------------------------- 1 | test = int(input()) 2 | while test > 0 : 3 | n,t = [int(x) for x in input().split()] 4 | q = input() 5 | q = list(q) 6 | i = 0 7 | while(i < t) : 8 | for j in range(n-1) : 9 | if q[j] == 'G' and q[j+1] == 'L' : 10 | q[j],q[j+i] = q[j+1],q[j] 11 | i += 1 12 | print(len(q)) 13 | print(''.join(q)) 14 | test -= 1 15 | 16 | ''' 17 | for _ in range(int(input())): 18 | n,t = map(int,input().split()) 19 | s = input() 20 | for i in range(t): 21 | s= s.replace("GL","LG") 22 | print(n) 23 | print(s) 24 | ''' 25 | -------------------------------------------------------------------------------- /CodeChef/Contest/List_Of_Books.py: -------------------------------------------------------------------------------- 1 | test = input("") 2 | books = raw_input("").split(" ") 3 | #for book in books : 4 | #book = int(book) 5 | 6 | n = input("") 7 | for i in range(n) : 8 | a = input("") 9 | print books[a - 1] 10 | books.pop(a - 1) 11 | -------------------------------------------------------------------------------- /CodeChef/Contest/March CookOff 2020/Find_Your_Gift.py: -------------------------------------------------------------------------------- 1 | test = int(input()) 2 | while test > 0 : 3 | n = int(input()) 4 | dir = input() 5 | x = 0 6 | y = 0 7 | for i in range(0,n) : 8 | if i == 0 : 9 | if dir[i] == 'L' : 10 | x -= 1 11 | elif dir[i] == 'R' : 12 | x += 1 13 | elif dir[i] == 'U' : 14 | y += 1 15 | else : 16 | y -= 1 17 | else : 18 | if dir[i] == 'L' and dir[i-1] != 'L' and dir[i - 1] != 'R': 19 | x -= 1 20 | elif dir[i] == 'R' and dir[i - 1] != 'R' and dir[i-1] != 'L' : 21 | x += 1 22 | elif dir[i] == 'U' and dir[i - 1] != 'U' and dir[i-1] != 'D' : 23 | y += 1 24 | elif dir[i] == 'D' and dir[i - 1] != 'D' and dir[i-1] != 'U' : 25 | y -= 1 26 | print(x,y) 27 | test -= 1 28 | -------------------------------------------------------------------------------- /CodeChef/Contest/Reverse.py: -------------------------------------------------------------------------------- 1 | n = input() 2 | lines = [] 3 | for i in range(n): 4 | string = raw_input("").replace(",", '').replace(";", "").replace("'", '').replace('.', '').replace(':', '').strip(" ").split(" ") 5 | string.reverse() 6 | lines.append(string) 7 | for i in reversed(lines): 8 | print(" ".join(i)) 9 | -------------------------------------------------------------------------------- /CodeChef/Contest/Sahil_Loves_Good_Scorer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int sum(int arr[], int n) 5 | { 6 | int sum = 0; 7 | for (int i = 0; i < n; i++) 8 | sum += arr[i]; 9 | return sum; 10 | } 11 | 12 | int main() 13 | { 14 | int test; 15 | scanf("%d",&test); 16 | while(test > 0) 17 | { 18 | int m,n; 19 | scanf("%d%d",&m,&n); 20 | int c1[m]; 21 | int c2[n]; 22 | for(int i = 0;i < m;i++) 23 | { 24 | scanf("%d",&c1[i]); 25 | } 26 | for(int i = 0;i < n;i++) 27 | { 28 | scanf("%d",&c2[i]); 29 | } 30 | if(sum(c1,m) > sum(c2,n)) 31 | { 32 | printf("C1"); 33 | } 34 | else 35 | { 36 | printf("C2"); 37 | } 38 | printf("\n"); 39 | test --; 40 | } 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /CodeChef/Contest/Zero_One_Tiles.py: -------------------------------------------------------------------------------- 1 | n1,n2 = 1,0 2 | n = input("") 3 | for i in range(n) : 4 | n2,n1 = n1,(n1 + n2) % 15746 5 | 6 | print n1 7 | -------------------------------------------------------------------------------- /CodeChef/Contest/ascii_to_char.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | # Auto-generated code below aims at helping you parse 5 | # the standard input according to the problem statement. 6 | 7 | message = input().split("32") 8 | new_l =[] 9 | for i in message : 10 | new_l.append(list(map(int,i.split()))) 11 | 12 | print (new_l) 13 | 14 | 15 | for i in new_l : 16 | for j in range(len(i)) : 17 | print(chr(i[j]),end = "") 18 | print(" ",end="") 19 | -------------------------------------------------------------------------------- /CodeChef/Contest/dynamo.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | import sys 3 | import os 4 | import math 5 | 6 | 7 | test = int(input("")) 8 | while(test > 0) : 9 | n = int(input("")) 10 | a = int(input("")) 11 | print(2 * pow(10,n) + a) 12 | b = int(input("")) 13 | print(pow(10,n) -b) 14 | d = int(input("")) 15 | print(pow(10,n) - d) 16 | last = int(input("")) 17 | sys.stdout.flush() 18 | if(last == -1) : 19 | sys.exit() 20 | test -=1 21 | -------------------------------------------------------------------------------- /CodeChef/Easy/A_Very_Easy_Problem.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | print("137=2(2(2)+2+2(0))+2(2+2(0))+2(0)") 3 | print("1315=2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0)") 4 | print("73=2(2(2)+2)+2(2+2(0))+2(0)") 5 | print("136=2(2(2)+2+2(0))+2(2+2(0))") 6 | print("255=2(2(2)+2+2(0))+2(2(2)+2)+2(2(2)+2(0))+2(2(2))+2(2+2(0))+2(2)+2+2(0)") 7 | print("1384=2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2)+2(2(2)+2(0))+2(2+2(0))") 8 | print("16385=2(2(2+2(0))+2(2)+2)+2(0)") 9 | #this is very easy problem 10 | -------------------------------------------------------------------------------- /CodeChef/Easy/Arranging_Cup_Cakes.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | int main() 7 | { 8 | long int test; 9 | scanf("%ld",&test); 10 | while(test > 0) 11 | { 12 | long int n; 13 | scanf("%ld",&n); 14 | long int i = 0; 15 | for(i = sqrt(n);i >= 1;i--) 16 | { 17 | if(n % i == 0) 18 | { 19 | printf("%ld\n",n/i - i); 20 | break; 21 | } 22 | } 23 | test -= 1; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /CodeChef/Easy/Bear_And_Extra_Number.py: -------------------------------------------------------------------------------- 1 | test = int(input()) 2 | while test > 0 : 3 | n = int(input()) 4 | l = list(map(int,input().split())) 5 | l.sort() 6 | for i in range(1,n) : 7 | if(l[i] == l[i - 1]) : 8 | print(l[i]) 9 | break 10 | else : 11 | if(l[0] + 1 not in l) : 12 | print(l[0]) 13 | else : 14 | print(l[-1]) 15 | test -= 1 16 | -------------------------------------------------------------------------------- /CodeChef/Easy/Caravans.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() 7 | { 8 | int test; 9 | cin >> test; 10 | while(test > 0) 11 | { 12 | int n; 13 | cin >> n; 14 | int arr[n]; 15 | for(int i = 0;i < n;i++) cin >> arr[i]; 16 | int count = 0; 17 | for(int i = 1;i < n;i++) 18 | { 19 | if(arr[i] > arr[i-1]) 20 | { 21 | count++; 22 | arr[i] = arr[i-1]; 23 | } 24 | } 25 | cout << n - count << endl; 26 | test --; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CodeChef/Easy/Chef_And_Easy_Problem.py: -------------------------------------------------------------------------------- 1 | test = int(input()) 2 | while test > 0 : 3 | n = int(input()) 4 | l = list(map(int,input().split())) 5 | l.sort() 6 | l.reverse() 7 | count = 0 8 | for i in range(0,n,2) : 9 | count += l[i] 10 | print(count) 11 | test -= 1 12 | -------------------------------------------------------------------------------- /CodeChef/Easy/Chef_And_Notebooks.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | test = int(input()) 3 | while test > 0 : 4 | count = 0 5 | x,y,k,n = map(int,input().split()) 6 | diff = (x - y) 7 | while n > 0 : 8 | p,c = map(int,input().split()) 9 | if(p >= diff) : 10 | if(c <= k) : 11 | count += 1 12 | n -= 1 13 | if(count > 0) : 14 | print("LuckyChef") 15 | else : 16 | print ("UnluckyChef") 17 | test -= 1 18 | -------------------------------------------------------------------------------- /CodeChef/Easy/Chef_Jumping.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | a = int(input()) 3 | 4 | if(a%3 == 0 or a%6 == 1) : 5 | print("yes") 6 | else : 7 | print("no") 8 | -------------------------------------------------------------------------------- /CodeChef/Easy/Count_Substrings.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int test; 8 | scanf("%d",&test); 9 | while(test > 0) 10 | { 11 | char str[100000]; 12 | long long int n; 13 | scanf("%lld",&n); 14 | scanf("%s",str); 15 | long long int count = 0; 16 | long long int i = 0; 17 | for(;i < n;i++) 18 | { 19 | if(str[i] == '1') 20 | { 21 | count ++; 22 | } 23 | } 24 | long long int num = (count * (count - 1))/2 + count; 25 | printf("%lld\n",num); 26 | test --; 27 | } 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /CodeChef/Easy/Counting_Pretty_Numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int test; 8 | scanf("%d",&test); 9 | while(test > 0) 10 | { 11 | int l,r; 12 | scanf("%d %d",&l,&r); 13 | int i = 0; 14 | int count = 0; 15 | for(i = l;i <= r;i++) 16 | { 17 | if(i%10 == 2 || i%10 == 3 || i%10 == 9) 18 | { 19 | count ++; 20 | } 21 | } 22 | printf("%d\n",count); 23 | test --; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /CodeChef/Easy/Disperancies_In_Voters_List.py: -------------------------------------------------------------------------------- 1 | n1, n2, n3 = map(int, input().split()) 2 | list1 = list() 3 | list2 = list() 4 | list3 = list() 5 | for i in range(n1): 6 | list1.append(int(input())) 7 | for i in range(n2): 8 | list2.append(int(input())) 9 | for i in range(n3): 10 | list3.append(int(input())) 11 | output = list() 12 | list1 = set(list1) 13 | list2 = set(list2) 14 | list3 = set(list3) 15 | final_list = list(list1 & list2) 16 | final_list += list(list1 & list3) 17 | final_list += list(list2 & list3) 18 | output = sorted(list(set(final_list))) 19 | print(len(output)) 20 | for i in output: 21 | print(i) 22 | -------------------------------------------------------------------------------- /CodeChef/Easy/Dividing_Sums.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | long int n; 8 | scanf("%ld",&n); 9 | long int i; 10 | long int arr[n]; 11 | long int sum = 0; 12 | for(i = 0;i < n;i++) 13 | { 14 | scanf("%ld",&arr[i]); 15 | sum += arr[i]; 16 | } 17 | long int reqsum = (n * (n + 1))/2; 18 | if(sum == reqsum) 19 | { 20 | printf("YES\n"); 21 | } 22 | else 23 | { 24 | printf("NO\n"); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /CodeChef/Easy/Factorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | int main() 8 | { 9 | int test; 10 | scanf("%d",&test); 11 | while(test > 0) 12 | { 13 | long long int n; 14 | scanf("%lld",&n); 15 | long long int i = 0; 16 | long long int zeroes = 0; 17 | long long int x = 5; 18 | for(i = 0;i < 100;i++) 19 | { 20 | if(x > n) 21 | { 22 | break; 23 | } 24 | else 25 | { 26 | zeroes += n/x; 27 | x = x * 5; 28 | } 29 | } 30 | printf("%lld\n",zeroes); 31 | test --; 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /CodeChef/Easy/Jewels_And_Stones.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | test = int(input()) 3 | while test > 0 : 4 | count = 0 5 | jewels = input() 6 | mined = input() 7 | #mined2 = set(mined) 8 | #jewel2 = set(jewels) 9 | for i in mined : 10 | if i in jewels : 11 | count += 1 12 | print (count) 13 | test -= 1 14 | -------------------------------------------------------------------------------- /CodeChef/Easy/Lapindromes.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | test = int(input()) 3 | while test > 0 : 4 | str = input() 5 | n = len(str) 6 | str = list(str) 7 | if n%2 == 0 : 8 | left = str[:n//2] 9 | right = str[n//2:] 10 | else : 11 | left = str[:n//2] 12 | right = str[n//2+1:] 13 | flag = 0 14 | #print(left,right) 15 | for i in left : 16 | if i in right : 17 | right.remove(i) 18 | continue 19 | else : 20 | flag = 1 21 | break 22 | if flag == 1 : 23 | print("NO") 24 | else : 25 | print("YES") 26 | 27 | test -= 1 28 | -------------------------------------------------------------------------------- /CodeChef/Easy/Life_Universe_And_Everything.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int num; 8 | cin >> num; 9 | while(num != 42) 10 | { 11 | cout << num << endl; 12 | cin >> num; 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /CodeChef/Easy/Life_Universe_And_Everything.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | while(1) : 3 | n = int(input()) 4 | if n == 42 : 5 | break 6 | else : 7 | print (n) 8 | -------------------------------------------------------------------------------- /CodeChef/Easy/Maximum_Weight_Difference.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | test = int(input()) 3 | while test > 0 : 4 | n,k = map(int,input().split()) 5 | l = list(map(int,input().split())) 6 | l.sort() 7 | if k > n//2 : 8 | k = n - k 9 | son = sum(l[:k]) 10 | chef = sum(l[k:n]) 11 | print(abs(chef - son)) 12 | test -= 1 13 | -------------------------------------------------------------------------------- /CodeChef/Easy/Prime_Generator.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int test; 8 | scanf("%d",&test); 9 | while(test > 0) 10 | { 11 | int n,m; 12 | scanf("%d%d",&n,&m); 13 | int i,j; 14 | for(i = n;i <=m ;i++) 15 | { 16 | int count = 0; 17 | for(j = 2;j <= sqrt(i);j++) 18 | { 19 | if(i%j == 0) 20 | { 21 | count ++; 22 | break; 23 | } 24 | } 25 | if(count == 0 && i != 1) 26 | { 27 | printf("%d\n",i); 28 | } 29 | } 30 | test --; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /CodeChef/Easy/Racing_Horses.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | test = int(input()) 3 | while test > 0 : 4 | n = int(input()) 5 | l = list(map(int,input().split())) 6 | l.sort() 7 | mini = l[1] - l[0] 8 | for j in range(n-1) : 9 | if 0 <= l[j+1] - l[j] < mini : 10 | mini = l[j+1] - l[j] 11 | print (mini) 12 | test -= 1 13 | -------------------------------------------------------------------------------- /CodeChef/Easy/Reverse_integer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int test; 8 | cin >> test; 9 | while(test--) 10 | { 11 | int n; 12 | cin >> n; 13 | int reverse = 0; 14 | while(n > 0) 15 | { 16 | reverse *= 10; 17 | reverse = (reverse + n%10); 18 | n = n/10; 19 | } 20 | cout << reverse << endl; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /CodeChef/Easy/Uncle_Johny.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | test = int(input()) 3 | while test > 0 : 4 | n = int(input()) 5 | l = list(map(int,input().split())) 6 | x = int(input()) 7 | a = l[x-1] 8 | l.sort() 9 | for i in range(n) : 10 | if l[i] == a : 11 | print (i+1) 12 | break 13 | test -= 1 14 | -------------------------------------------------------------------------------- /CodeChef/Medium/Coin_Flip.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() 7 | { 8 | int test; 9 | cin >> test; 10 | while(test--) 11 | { 12 | int g; 13 | cin >> g; 14 | for(int i = 0;i < g;i++) 15 | { 16 | int ini,n,q; 17 | cin >> ini >> n >> q; 18 | if(n%2 == 0 || ini == q) cout << n/2 << endl; 19 | else cout << (n/2 + 1) << endl; 20 | } 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /CodeChef/Medium/Laddu.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | test = int(input()) 3 | while test > 0 : 4 | total,origin = input().split() 5 | total = int(total) 6 | ladoos = 0 7 | while total > 0 : 8 | read = list(input().split()) 9 | if read[0] == "CONTEST_WON" : 10 | ladoos += 300 11 | read[1] = int(read[1]) 12 | if(read[1] < 20) : 13 | ladoos += 20 - read[1] 14 | elif read[0] == "TOP_CONTRIBUTOR" : 15 | ladoos += 300 16 | elif read[0] == "BUG_FOUND" : 17 | ladoos += int(read[1]) 18 | else : 19 | ladoos += 50 20 | total -= 1 21 | if(origin == "INDIAN") : 22 | print(ladoos//200) 23 | else : 24 | print(ladoos//400) 25 | test -= 1 26 | -------------------------------------------------------------------------------- /CodeChef/Medium/Smart_Phone.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | long long n; 7 | cin >> n; 8 | long long arr[n]; 9 | long long i,j = n; 10 | for(i = 0;i < n;i++) cin >> arr[i]; 11 | sort(arr,arr + n); 12 | long long sumarr[n]; 13 | long long maxi = INT_MIN; 14 | for(int i = 0;i < n;i++,j--) 15 | { 16 | sumarr[i] = arr[i] * j; 17 | maxi = max(maxi,sumarr[i]); 18 | } 19 | cout << maxi << endl; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /CodeChef/Medium/Trailing_zeroes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | long long test; 8 | cin >> test; 9 | while(test--) 10 | { 11 | long long n; 12 | cin >> n; 13 | long long zeroes = 0; 14 | for(int i = 5;n/i >= 1;i = i * 5) 15 | { 16 | zeroes += n/i; 17 | } 18 | cout << zeroes << endl; 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /CodeChef/beginner/ATM: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int wamt; 4 | float tamt; 5 | scanf("%d %f",&wamt,&tamt); 6 | if(wamt % 5 != 0){ 7 | printf("%.2f",tamt); 8 | } 9 | else{ 10 | if(wamt + 0.5 > tamt){ 11 | printf("%.2f",tamt); 12 | } 13 | if(wamt + 0.5 < tamt){ 14 | float rem = tamt - wamt - 0.50; 15 | printf("%.2f",rem); 16 | } 17 | if(wamt == 0){ 18 | printf("%.2f",tamt); 19 | } 20 | } 21 | return 0; 22 | } 23 | 24 | //this is a begginer question. 25 | -------------------------------------------------------------------------------- /CodeChef/beginner/ATM2_C: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t; 6 | scanf("%d",&t); 7 | while(t --) 8 | { 9 | int n,k; 10 | scanf("%d %d",&n,&k); 11 | int money[n]; 12 | int i = 0; 13 | for(i = 0;i < n;i++) 14 | { 15 | scanf("%d",&money[i]); 16 | } 17 | int mon[n]; 18 | int z = 0; 19 | for(i = 0;i < n;i++) 20 | { 21 | if(money[i] <= k) 22 | { 23 | mon[z++] = 1; 24 | k = k - money[i]; 25 | } 26 | else 27 | { 28 | mon[z++] = 0; 29 | } 30 | } 31 | for(z = 0;z < n;z++) 32 | { 33 | printf("%d",mon[z]); 34 | } 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /CodeChef/beginner/Addition.py: -------------------------------------------------------------------------------- 1 | def add(a,b) : 2 | count = 0 3 | while ( b > 0 ) : 4 | count += 1 5 | u = a ^ b 6 | v = a & b 7 | a = u 8 | b = 2 * v 9 | return count 10 | 11 | 12 | if __name__ == "__main__" : 13 | test = input("") 14 | while(test > 0) : 15 | a = input("") 16 | b = input("") 17 | print (add(a,b)) 18 | test -= 1 19 | -------------------------------------------------------------------------------- /CodeChef/beginner/AreaOrPerimeter_C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) { 5 | int l,b; 6 | scanf("%d\n",&l); 7 | scanf("%d",&b); 8 | int peri = 2 * (l + b); 9 | int area = (l * b); 10 | if(peri > area) 11 | { 12 | printf("Peri\n%d",peri); 13 | } 14 | else if(area > peri) 15 | { 16 | printf("Area\n%d",area); 17 | } 18 | else 19 | { 20 | printf("Eq\n%d",peri); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /CodeChef/beginner/Buying_New_Tablet.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | test = int(input()) 3 | while test > 0 : 4 | n,b = map(int,input().split()) 5 | l = [] 6 | while n > 0 : 7 | parameters = list(map(int,input().split())) 8 | l.append(parameters) 9 | n -= 1 10 | maxi = 0 11 | for items in l : 12 | if(items[1]*items[0] >= maxi and items[2] <= b) : 13 | maxi = items[1] * items[0] 14 | 15 | if maxi == 0 : 16 | print ("no tablet") 17 | else : 18 | print (maxi) 19 | 20 | #print (l) 21 | test -= 1 22 | -------------------------------------------------------------------------------- /CodeChef/beginner/ChefAndDigitsOfANumber_Python: -------------------------------------------------------------------------------- 1 | t = input("") 2 | 3 | while(t > 0): 4 | a = raw_input("") 5 | count1 = 0 6 | count0 = 0 7 | for i in a: 8 | if i == '1': 9 | count1 += 1 10 | else: 11 | count0 += 1 12 | if(count0 == 1 or count1 == 1): 13 | print "Yes" 14 | else: 15 | print "No" 16 | t -= 1 17 | -------------------------------------------------------------------------------- /CodeChef/beginner/ChefAndDolls: -------------------------------------------------------------------------------- 1 | t = input("") 2 | 3 | while(t > 0): 4 | n = input("") 5 | l1 = [] 6 | while(n > 0): 7 | a = input("") 8 | l1.append(a) 9 | n -= 1 10 | d = {} 11 | for x in l1: 12 | if x not in d: 13 | d[x] = 1 14 | else: 15 | d[x] += 1 16 | for x in d: 17 | if(d[x] % 2 != 0): 18 | print x 19 | t -= 1 20 | -------------------------------------------------------------------------------- /CodeChef/beginner/ChefAndSnackDown_C: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t; 6 | scanf("%d",&t); 7 | while(t --) 8 | { 9 | int year; 10 | scanf("%d",&year); 11 | if(year == 2010 || year == 2015 || year == 2016 || year == 2017 || year == 2019) 12 | { 13 | printf("HOSTED"); 14 | } 15 | else 16 | { 17 | printf("NOT HOSTED"); 18 | } 19 | printf("\n"); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /CodeChef/beginner/ChefAndTableTennis_Python: -------------------------------------------------------------------------------- 1 | t = input("") 2 | 3 | while(t > 0): 4 | s = raw_input("") 5 | count_1 = 0 6 | count_0 = 0 7 | for i in s: 8 | if i == '1': 9 | count_1 += 1 10 | else: 11 | count_0 += 1 12 | if(count_1 > count_0): 13 | print "WIN" 14 | else: 15 | print "LOSE" 16 | t -= 1 17 | -------------------------------------------------------------------------------- /CodeChef/beginner/Chef_And_Coloring.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | test = int(input("")) 3 | while test > 0 : 4 | n = int(input()) 5 | color = list(input()) 6 | uni = set(color) 7 | c = [color.count(i) for i in uni] 8 | #print(c) 9 | #print (uni) 10 | print(n - max(c)) 11 | test -= 1 12 | -------------------------------------------------------------------------------- /CodeChef/beginner/Chef_And_Eid.py: -------------------------------------------------------------------------------- 1 | test = int(input()) 2 | while test > 0 : 3 | n = int(input()) 4 | l = list(map(int,input().split())) 5 | l.sort() 6 | minimum = 100000 7 | for i in range(n - 1) : 8 | if(l[i + 1] - l[i] < minimum) : 9 | minimum = l[i + 1] - l[i] 10 | print(minimum) 11 | test -= 1 12 | -------------------------------------------------------------------------------- /CodeChef/beginner/Chef_And_Remissness.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int maxtimes(int a,int b) 6 | { 7 | return a + b; 8 | } 9 | 10 | int mintimes(int a,int b) 11 | { 12 | if(a > b) 13 | { 14 | return a; 15 | } 16 | else 17 | { 18 | return b; 19 | } 20 | } 21 | 22 | 23 | int main() 24 | { 25 | int test; 26 | scanf("%d",&test); 27 | while(test > 0) 28 | { 29 | int a,b; 30 | scanf("%d %d",&a,&b); 31 | { 32 | printf("%d %d\n",mintimes(a, b),maxtimes(a, b)); 33 | } 34 | test --; 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /CodeChef/beginner/Coins_and_Triangles.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | int main() 7 | { 8 | int test; 9 | scanf("%d",&test); 10 | while(test > 0) 11 | { 12 | int n; 13 | int sum = 0; 14 | scanf("%d",&n); 15 | for(int i = 0;i <= n;i++) 16 | { 17 | sum = i * (i + 1)/2; 18 | if(sum > n) 19 | { 20 | printf("%d",i - 1); 21 | break ; 22 | } 23 | } 24 | printf("\n"); 25 | test --; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /CodeChef/beginner/DecrementOrIncrement_C: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main() 5 | { 6 | int n; 7 | scanf("%d",&n); 8 | if(n % 4 == 0) 9 | { 10 | printf("%d",n + 1); 11 | } 12 | else 13 | { 14 | printf("%d",n - 1); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /CodeChef/beginner/Discount_Shop.py: -------------------------------------------------------------------------------- 1 | t = input("") 2 | while(t > 0) : 3 | a = raw_input("") 4 | l = [] 5 | for i in range(len(a)) : 6 | s = a[:i] + a[i + 1 :] 7 | l.append(int(s)) 8 | print min(l) 9 | t -= 1 10 | -------------------------------------------------------------------------------- /CodeChef/beginner/Find_The_Maximum_Value.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | test = int(input()) 3 | while test > 0 : 4 | l = list(map(int,input().split())) 5 | for i in l : 6 | if(i == len(l) - 1) : 7 | l.remove(i) 8 | print(max(l)) 9 | break 10 | test -= 1 11 | -------------------------------------------------------------------------------- /CodeChef/beginner/From_Heaven_To_Earth.py: -------------------------------------------------------------------------------- 1 | import math 2 | test=int(input()) 3 | while test > 0 : 4 | n,v,u=map(int,input().split(" ")) 5 | m=math.sqrt(2)*n 6 | if (n+n)/u<=m/v: 7 | print("Elevator") 8 | else: 9 | print("Stairs") 10 | test -= 1 11 | -------------------------------------------------------------------------------- /CodeChef/beginner/GCDandLCM_C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | long gcd(long a,long b) 6 | { 7 | if(a == 0) 8 | { 9 | return b; 10 | } 11 | else 12 | { 13 | return gcd(b % a,a); 14 | } 15 | } 16 | 17 | 18 | long lcm(long a,long b) 19 | { 20 | return (a * b)/gcd(a,b); 21 | } 22 | 23 | int main() 24 | { 25 | long t; 26 | scanf("%ld",&t); 27 | while(t--) 28 | { 29 | long a,b; 30 | scanf("%ld %ld",&a,&b); 31 | printf("%ld %ld\n",gcd(a,b),lcm(a,b)); 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /CodeChef/beginner/Good_Joke.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int test; 7 | scanf("%d",&test); 8 | while(test > 0) 9 | { 10 | int n; 11 | scanf("%d",&n); 12 | int a,b; 13 | int ans = 1; 14 | scanf("%d %d",&a,&b); 15 | for(int i = 2;i < n + 1;i++) 16 | { 17 | scanf("%d %d",&a,&b); 18 | ans ^= i; 19 | } 20 | printf("%d\n",ans); 21 | test --; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /CodeChef/beginner/GradeTheSteel: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t; 6 | scanf("%d",&t); 7 | while(t--) 8 | { 9 | double hard,carb,tens; 10 | scanf("%lf %lf %lf",&hard,&carb,&tens); 11 | if(hard > 50 && carb < 0.7 && tens>5600) 12 | printf("10"); 13 | else if(hard > 50 && carb < 0.7) 14 | printf("9"); 15 | else if(carb < 0.7 && tens > 5600) 16 | printf("8"); 17 | else if(hard > 50 && tens > 5600) 18 | printf("7"); 19 | else if(hard > 50 || carb < 0.7 || tens > 5600) 20 | printf("6"); 21 | else 22 | printf("5"); 23 | printf("\n"); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /CodeChef/beginner/Help_Lost_Robot.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | 7 | int main() 8 | { 9 | int test; 10 | scanf("%d",&test); 11 | while(test > 0) 12 | { 13 | int x1,y1,x2,y2; 14 | scanf("%d %d %d %d",&x1,&y1,&x2,&y2); 15 | if(x2 - x1 >= 1 && y2 - y1 == 0) 16 | { 17 | printf("right"); 18 | } 19 | else if(x1 - x2 >= 1 && y2 - y1 == 0) 20 | { 21 | printf("left"); 22 | } 23 | else if(y2 - y1 >= 1 && x2 - x1 == 0) 24 | { 25 | printf("up"); 26 | } 27 | else if(y1 - y2 >= 1 && x2 - x1 == 0) 28 | { 29 | printf("down"); 30 | } 31 | else 32 | { 33 | printf("sad"); 34 | } 35 | printf("\n"); 36 | test --; 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /CodeChef/beginner/MalavikaAndBalloons_C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int t; 8 | scanf("%d",&t); 9 | while(t --) 10 | { 11 | int count_a = 0,count_b = 0; 12 | char *str; 13 | str = (char *)malloc(1000); 14 | scanf("%s",str); 15 | while(*str != '\0') 16 | { 17 | if(*str == 'a') 18 | { 19 | count_a ++; 20 | } 21 | else 22 | { 23 | count_b ++; 24 | } 25 | str++; 26 | } 27 | int min = count_a; 28 | if(count_b < min) 29 | { 30 | min = count_b; 31 | } 32 | printf("%d\n",min); 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /CodeChef/beginner/Mutated_Minions.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int test; 8 | scanf("%d",&test); 9 | while(test > 0) 10 | { 11 | int n,d; 12 | scanf("%d%d",&n,&d); 13 | int arr[n]; 14 | int i = 0; 15 | int count = 0; 16 | for(i = 0;i < n;i++) 17 | { 18 | scanf("%d",&arr[i]); 19 | if((arr[i] + d)%7 == 0) 20 | { 21 | count += 1; 22 | } 23 | } 24 | printf("%d\n",count); 25 | test --; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /CodeChef/beginner/NoOfDigits_C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) { 5 | int n; 6 | int count = 0; 7 | scanf("%d",&n); 8 | while(n != 0) 9 | { 10 | count ++; 11 | n = n/10; 12 | } 13 | if(count == 1) 14 | { 15 | printf("1"); 16 | } 17 | else if(count == 2) 18 | { 19 | printf("2"); 20 | } 21 | else if(count == 3) 22 | { 23 | printf("3"); 24 | } 25 | else 26 | { 27 | printf("More than 3 digits"); 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /CodeChef/beginner/PackagingCupcakes.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | //FIRST TRY 7 | /* 8 | int main() 9 | { 10 | int test; 11 | scanf("%d",&test); 12 | while(test > 0) 13 | { 14 | int n; 15 | scanf("%d",&n); 16 | int arr[1]; 17 | int maxi = 0; 18 | int i = 1; 19 | for(i = n/2;i <= n;i++) 20 | { 21 | if(n % i >= maxi) 22 | { 23 | arr[0] = i; 24 | maxi = n % i ; 25 | } 26 | } 27 | printf("%d",arr[0]); 28 | test --; 29 | } 30 | return 0; 31 | } 32 | */ 33 | 34 | 35 | int main() 36 | { 37 | int test; 38 | scanf("%d",&test); 39 | while(test > 0) 40 | { 41 | int n; 42 | scanf("%d",&n); 43 | printf("%d\n",(n/2)+ 1); 44 | test --; 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /CodeChef/beginner/ProgramYourOwnCalculator_C: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | double a,b; 6 | char operator; 7 | scanf("%lf\n%lf\n%c",&a,&b,&operator); 8 | if(operator == '+') 9 | { 10 | printf("%lf",a + b); 11 | } 12 | else if(operator == '-') 13 | { 14 | printf("%lf",a - b); 15 | } 16 | else if(operator == '*') 17 | { 18 | printf("%lf",a * b); 19 | } 20 | else 21 | { 22 | printf("%lf",a/b); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /CodeChef/beginner/Puppy_And_Sum.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int sum(int n) 6 | { 7 | return n * (n + 1)/2; 8 | } 9 | 10 | int main() 11 | { 12 | int test; 13 | scanf("%d",&test); 14 | while ( test > 0 ) 15 | { 16 | int n,k; 17 | scanf("%d %d",&k,&n); 18 | for(int i = 0;i < k;i++) 19 | { 20 | n = sum(n); 21 | } 22 | printf("%d\n",n); 23 | test --; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /CodeChef/beginner/Rectangle_C: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int t; 5 | scanf("%d",&t); 6 | while(t --) 7 | { 8 | int a,b,c,d; 9 | scanf("%d %d %d %d",&a,&b,&c,&d); 10 | if(a == b && d == c) 11 | { 12 | printf("YES"); 13 | } 14 | else if(a == c && b == d) 15 | { 16 | printf("YES"); 17 | } 18 | else if(a == d && b == c) 19 | { 20 | printf("YES"); 21 | } 22 | else if(a == b && b == c && c == d) 23 | { 24 | printf("YES"); 25 | } 26 | else 27 | { 28 | printf("NO"); 29 | } 30 | printf("\n"); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /CodeChef/beginner/Roots_Of_Quadratic_Equations.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | import math 3 | a = int(input()) 4 | b = int(input()) 5 | c = int(input()) 6 | d = math.sqrt((b*b) - (4*a*c)) 7 | x = (-b + d)/(2 * a) 8 | y = (-b - d)/(2 * a) 9 | print (x) 10 | print (y) 11 | -------------------------------------------------------------------------------- /CodeChef/beginner/StudyingAlphabet_Python: -------------------------------------------------------------------------------- 1 | s = raw_input("") 2 | t = input("") 3 | 4 | while(t > 0): 5 | count = 0 6 | s2 = raw_input("") 7 | for i in s2: 8 | if i in s: 9 | count += 1 10 | 11 | if count == len(s2): 12 | print "Yes" 13 | else: 14 | print "No" 15 | t -= 1; 16 | -------------------------------------------------------------------------------- /CodeChef/beginner/SumOrDifference_C: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n1,n2; 6 | scanf("%d",&n1); 7 | scanf("%d",&n2); 8 | if(n1 > n2) 9 | { 10 | printf("%d",n1 - n2); 11 | } 12 | else 13 | { 14 | printf("%d",n1 + n2); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /CodeChef/beginner/Tanu_And_HeadBob.py: -------------------------------------------------------------------------------- 1 | t = input("") 2 | 3 | while (t > 0) : 4 | n = input("") 5 | nods = raw_input("") 6 | count_n = 0 7 | count_i = 0 8 | for nod in nods : 9 | if nod == 'N' : 10 | count_n += 1 11 | elif nod == 'I' : 12 | count_i += 1 13 | if count_n == n : 14 | print "NOT SURE" 15 | elif count_i > 0 : 16 | print "INDIAN" 17 | else : 18 | print "NOT INDIAN" 19 | t -= 1 20 | -------------------------------------------------------------------------------- /CodeChef/beginner/TheLeadGame_Python: -------------------------------------------------------------------------------- 1 | T = input("") 2 | p1 = 0 3 | p2 = 0 4 | d = {} 5 | 6 | for i in range(T): 7 | s = raw_input() 8 | s = s.split(" ") 9 | 10 | p1 += int(s[0]) 11 | p2 += int(s[1]) 12 | 13 | if p1 > p2: 14 | d[p1 - p2] = 1 15 | else : 16 | d[p2 - p1] = 2 17 | 18 | 19 | m = 0; 20 | 21 | for t in d: 22 | if t > m: 23 | m = t 24 | 25 | print str(d[m]) + " " + str(m) 26 | -------------------------------------------------------------------------------- /CodeChef/beginner/TwoVsTen_C: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int t; 5 | scanf("%d",&t); 6 | while(t --) 7 | { 8 | int a; 9 | scanf("%d",&a); 10 | if(a % 10 == 0) 11 | { 12 | printf("0"); 13 | } 14 | else if(a % 5 == 0 && a % 10 != 0) 15 | { 16 | printf("1"); 17 | } 18 | else 19 | { 20 | printf("-1"); 21 | } 22 | printf("\n"); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /CodeChef/beginner/VowelOrConsonant: -------------------------------------------------------------------------------- 1 | s = raw_input("") 2 | vowel = ['A','E','I','O','U'] 3 | 4 | if s in vowel: 5 | print "Vowel" 6 | else: 7 | print "Consonant" 8 | -------------------------------------------------------------------------------- /CodeChef/peer/Matryoshka_Dolls.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | test = int(input()) 3 | while test > 0 : 4 | n = int(input()) 5 | l = list(map(int,input().split())) 6 | l.sort() 7 | count = 0 8 | for i in range(n - 1) : 9 | if l[i] == l[i + 1] : 10 | print("NO") 11 | break 12 | else : 13 | count += 1 14 | if count == n - 1 : 15 | print("YES") 16 | test -= 1 17 | #dish cooked ready to eat 18 | -------------------------------------------------------------------------------- /CodeChef/peer/Minimizing_The_Dot_Product.py: -------------------------------------------------------------------------------- 1 | test = int(input()) 2 | while test > 0 : 3 | n = int(input()) 4 | a = list(map(int,input().split())) 5 | b = list(map(int,input().split())) 6 | a.sort() 7 | b.sort() 8 | b.reverse() 9 | dot = 0 10 | for i in range(n) : 11 | dot += a[i] * b[i] 12 | print(dot) 13 | test -= 1 14 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Balanced_Array.cpp: -------------------------------------------------------------------------------- 1 | //https://practice.geeksforgeeks.org/problems/balanced-array/0 2 | int main() { 3 | //code 4 | int test; 5 | cin >> test; 6 | while(test--) 7 | { 8 | int n; 9 | cin >> n; 10 | int arr[n]; 11 | for(int i = 0;i < n;i++) 12 | { 13 | cin >> arr[i]; 14 | } 15 | int sumleft = 0,sumright = 0; 16 | int mid = n/2; 17 | for(int i = 0;i < mid;i++) 18 | sumleft += arr[i]; 19 | for(int i = mid;i < n;i++) 20 | sumright += arr[i]; 21 | cout << abs(sumleft - sumright) << endl; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Find_Min_Max.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | //code 7 | int test; 8 | cin >> test; 9 | while(test--) 10 | { 11 | int n; 12 | cin >> n; 13 | int arr[n]; 14 | for(int i = 0;i < n;i++) cin >> arr[i]; 15 | int mini = INT_MAX,maxi = INT_MIN; 16 | for(int i = 0;i < n;i++) 17 | { 18 | maxi = max(maxi,arr[i]); 19 | mini = min(mini,arr[i]); 20 | } 21 | cout << mini << " " << maxi << endl; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/First_And_Last_Occurance.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | //code 6 | int test; 7 | cin >> test; 8 | while(test--) 9 | { 10 | int n; 11 | cin >> n; 12 | int arr[n]; 13 | for(int i = 0;i < n;i++) cin >> arr[i]; 14 | int x; 15 | cin >> x; 16 | int i,flag = 0; 17 | for(i = 0;i < n;i++) 18 | { 19 | if(arr[i] == x) 20 | { 21 | flag = 1; 22 | break; 23 | } 24 | } 25 | if(flag == 0) cout << -1 << endl; 26 | else 27 | { 28 | cout << i << " "; 29 | while(arr[i] == x) 30 | { 31 | i++; 32 | } 33 | cout << i-1 << endl; 34 | } 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Game_With_NOs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | //code 7 | int test; 8 | cin >> test; 9 | while(test--) 10 | { 11 | int n; 12 | cin >> n; 13 | int arr[n],arrxor[n]; 14 | for(int i = 0;i < n;i++) cin >> arr[i]; 15 | int i; 16 | for(i = 0;i < n - 1;i++) 17 | { 18 | arrxor[i] = arr[i] ^ arr[i+1]; 19 | } 20 | arrxor[i] = arr[i]; 21 | for(i = 0;i < n;i++) cout << arrxor[i] << " "; 22 | cout << endl; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Immediate_Smaller_Element.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | //code 6 | int test; 7 | cin >> test; 8 | while(test--) 9 | { 10 | int n; 11 | cin >> n; 12 | int arr[n]; 13 | for(int i = 0;i < n;i++) 14 | cin >> arr[i]; 15 | for(int i = 0;i < n - 1;i++) 16 | { 17 | if(arr[i] > arr[i+1]) cout << arr[i+1] << " "; 18 | else cout << "-1 "; 19 | } 20 | cout << "-1" << endl; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Ishaan_Loves_Chocolates.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | //code 7 | int test; 8 | cin >> test; 9 | while(test--) 10 | { 11 | int n; 12 | cin >> n; 13 | int arr[n]; 14 | for(int i = 0;i < n;i++) cin >> arr[i]; 15 | int mini = INT_MAX; 16 | for(int i = 0;i < n;i++) 17 | { 18 | if(mini >= arr[i]) 19 | { 20 | mini = arr[i]; 21 | } 22 | } 23 | cout << mini << endl; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Kth_Smallest.cpp: -------------------------------------------------------------------------------- 1 | //https://practice.geeksforgeeks.org/problems/kth-smallest-element/0 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | //code 8 | int test; 9 | cin >> test; 10 | while(test--) 11 | { 12 | int n; 13 | cin >> n; 14 | int arr[n]; 15 | for(int i = 0;i < n;i++) 16 | { 17 | cin >> arr[i]; 18 | } 19 | int k; 20 | cin >> k; 21 | sort(arr,arr+n); 22 | cout << arr[k-1] << endl; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Learn_To_Comment.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | //Initial Template for C++ 3 | //Initial Template for C++ 4 | 5 | #include 6 | using namespace std; 7 | 8 | void comment(int,int,int); 9 | 10 | 11 | // } Driver Code Ends 12 | //User function Template for C++ 13 | 14 | //Comment the part that outputs b 15 | void comment(int a,int b,int c) 16 | { 17 | cout<> t; 30 | 31 | while(t--){ 32 | int a,b,c; 33 | cin>>a>>b>>c; 34 | comment(a,b,c); 35 | } 36 | 37 | return 0; 38 | } // } Driver Code Ends 39 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Linear_Search.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | //code 6 | int test; 7 | cin >> test; 8 | while(test--) 9 | { 10 | int n,x; 11 | cin >> n; 12 | int arr[n]; 13 | for(int i = 0;i < n;i++) cin >> arr[i]; 14 | cin >> x; 15 | int flag = 0; 16 | for(int i = 0;i < n;i++) 17 | { 18 | if(arr[i] == x) 19 | { 20 | cout << i << endl; 21 | flag = 1; 22 | break; 23 | } 24 | } 25 | if(flag == 0) cout << -1 << endl; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Majority_Element_notopt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | //code 7 | int test; 8 | cin >> test; 9 | while(test > 0) 10 | { 11 | int counter[1000000]; 12 | memset(counter,0,1000000); 13 | int n; 14 | int maxcount = 0; 15 | int element = 0; 16 | cin >> n; 17 | int arr[n]; 18 | for(int i = 0;i < n;i++) 19 | { 20 | cin >> arr[i]; 21 | counter[arr[i]] += 1; 22 | if(counter[arr[i]] > maxcount) 23 | { 24 | maxcount = counter[arr[i]]; 25 | element = arr[i]; 26 | } 27 | } 28 | 29 | if(maxcount > n/2) cout << element << endl; 30 | else cout << "-1" << endl; 31 | test --; 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Missing_Number_In_Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() 7 | { 8 | int test; 9 | cin >> test; 10 | while(test > 0) 11 | { 12 | int n; 13 | cin >> n; 14 | int arr[n-1]; 15 | int arrsum = 0; 16 | for(int i = 0;i < n-1;i++) 17 | { 18 | cin >> arr[i]; 19 | arrsum += arr[i]; 20 | } 21 | int sum = (n * (n + 1))/2; 22 | cout << sum - arrsum << endl; 23 | test--; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Multiply_LeftRight_Subarray.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | //code 6 | int test; 7 | cin >> test; 8 | while(test--) 9 | { 10 | int n; 11 | cin >> n; 12 | int arr[n]; 13 | for(int i = 0;i < n;i++) 14 | { 15 | cin >> arr[i]; 16 | } 17 | int mid = n/2; 18 | int suml = 0,sumr = 0; 19 | for(int i = 0;i < n/2;i++) 20 | suml += arr[i]; 21 | for(int i = n/2;i < n;i++) 22 | sumr += arr[i]; 23 | cout << suml * sumr << endl; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Play_With_OR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | //code 7 | int test; 8 | cin >> test; 9 | while(test--) 10 | { 11 | int n; 12 | cin >> n; 13 | int arr[n]; 14 | for(int i = 0;i < n;i++) cin >> arr[i]; 15 | int arror[n]; 16 | int i; 17 | for(i = 0;i < n - 1;i++) 18 | { 19 | arror[i] = arr[i] | arr[i+1]; 20 | } 21 | arror[i] = arr[n-1]; 22 | for(i = 0;i < n;i++) cout << arror[i] << " "; 23 | cout << endl; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Rotating_An_Array.py: -------------------------------------------------------------------------------- 1 | #code 2 | test = int(input()) 3 | while test > 0 : 4 | n = int(input()) 5 | l = list(map(int,input().split())) 6 | d = int(input()) 7 | l = l[d:] + l[:d] 8 | for i in range(n) : 9 | print(l[i],end = " ") 10 | print() 11 | test -= 1 12 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Searching_number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | //code 6 | int test; 7 | cin >> test; 8 | while(test--) 9 | { 10 | int n,x; 11 | cin >> n >> x; 12 | int arr[n]; 13 | int flag = 0; 14 | for(int i = 0;i < n;i++) cin >> arr[i]; 15 | for(int i = 0;i < n;i++) 16 | { 17 | if(arr[i] == x) 18 | { 19 | flag = 1; 20 | cout << i + 1 << endl; 21 | break; 22 | } 23 | } 24 | if(flag == 0) cout << -1 << endl; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Stuffs_Division.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | //code 7 | int test; 8 | cin >> test; 9 | while(test--) 10 | { 11 | int n; 12 | cin >> n; 13 | int arr[n]; 14 | int sum_need = 0; 15 | int sum_arr = 0; 16 | for(int i = 0;i < n;i++) 17 | { 18 | cin >> arr[i]; 19 | sum_arr += arr[i]; 20 | sum_need += (i+1); 21 | } 22 | if(sum_arr == sum_need) cout << "YES" << endl; 23 | else cout << "NO" << endl; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Sum_Of_Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | //code 7 | int test; 8 | cin >> test; 9 | while(test--) 10 | { 11 | int n; 12 | cin >> n; 13 | int arr[n]; 14 | int sum = 0; 15 | for(int i = 0;i < n;i++) 16 | { 17 | cin >> arr[i]; 18 | sum += arr[i]; 19 | } 20 | cout << sum << endl; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Sum_Of_f(a[i],a[j]).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | //code 8 | int test; 9 | cin >> test; 10 | while(test--) 11 | { 12 | int n; 13 | cin >> n; 14 | int arr[n]; 15 | for(int i = 0;i < n;i++) 16 | { 17 | cin >> arr[i]; 18 | } 19 | int i,j,sum = 0; 20 | for(i = 0;i < n;i++) 21 | { 22 | for(j = i + 1;j < n;j++) 23 | { 24 | if(abs(arr[i]-arr[j]) > 1) 25 | { 26 | sum += arr[j] - arr[i]; 27 | } 28 | else 29 | { 30 | sum += 0; 31 | } 32 | } 33 | } 34 | cout << sum << endl; 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/Two_Arrays_AreEqual.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | //code 7 | int test; 8 | cin >> test; 9 | while(test--) 10 | { 11 | int n; 12 | cin >> n; 13 | unsigned long long int arr1[n],arr2[n],sum1 = 0,sum2 = 0,res = 0,i; 14 | for(i = 0;i < n;i++) 15 | { 16 | cin >> arr1[i]; 17 | sum1 += arr1[i]; 18 | res ^= arr1[i]; 19 | } 20 | for(i = 0;i < n;i++) 21 | { 22 | cin >> arr2[i]; 23 | sum2 += arr2[i]; 24 | res^= arr2[i]; 25 | } 26 | if(res == 0 && sum1==sum2) cout << "1" << endl; 27 | else cout << "0" << endl; 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Geeks4Geeks/Array/XOR_Of_A_Given_Range.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int gtXor(int arr[], int n,int a,int b); 4 | int main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--){ 9 | int n,a,b; 10 | cin>>n>>a>>b; 11 | int arr[n]; 12 | for(int i=0;i>arr[i]; 14 | int m=min(a,b); 15 | int l=max(a,b); 16 | cout<left), height(node->right)); 11 | } 12 | -------------------------------------------------------------------------------- /Geeks4Geeks/Heap/Adding_Array_elements.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | //code 7 | int test; 8 | cin >> test; 9 | while(test--) 10 | { 11 | int n,mini; 12 | cin >> n >> mini; 13 | priority_queue , greater > pq; 14 | for(int i = 0;i < n;i++) 15 | { 16 | int num; 17 | cin >> num; 18 | pq.push(num); 19 | } 20 | while(pq.top() < mini) 21 | { 22 | int a = pq.top(); 23 | pq.pop(); 24 | int b = pq.top(); 25 | pq.pop(); 26 | pq.push(a + b); 27 | } 28 | while(!pq.empty()) 29 | { 30 | cout << pq.top() << " "; 31 | pq.pop(); 32 | } 33 | cout << endl; 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Geeks4Geeks/Heap/Height_Of_Heap.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | //code 7 | int test; 8 | cin >> test; 9 | while(test--) 10 | { 11 | int n; 12 | cin >> n; 13 | int heap[n]; 14 | for(int i = 0;i < n;++i) cin >> heap[i]; 15 | int height = 0; 16 | while(n > 1) 17 | { 18 | height += 1; 19 | n = n/2; 20 | } 21 | cout << height << endl; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Geeks4Geeks/Heap/Kth_Largest_Element.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int test; 7 | cin >> test; 8 | while(test--) 9 | { 10 | int n,x; 11 | cin >> n >> x; 12 | vector heap; 13 | for(int i = 0;i < n;i++) 14 | { 15 | int num; 16 | cin >> num; 17 | heap.push_back(num); 18 | } 19 | make_heap(heap.begin(),heap.end()); 20 | for(int i = 0;i < x;i++) 21 | { 22 | cout << heap.front() << " "; 23 | pop_heap(heap.begin(),heap.end()); 24 | heap.pop_back(); 25 | } 26 | cout << endl; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Geeks4Geeks/Misc/Replace_0_with_5.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | int convertFive(int n); 6 | 7 | // Driver program to test above function 8 | int main() { 9 | int T; 10 | cin >> T; 11 | while (T--) { 12 | int n; 13 | cin >> n; 14 | cout << convertFive(n) << endl; 15 | } 16 | }// } Driver Code Ends 17 | /*you are required to complete this method*/ 18 | int convertFive(int n) { 19 | // Your code here 20 | int i = 0,answer = n; 21 | while(n > 0) 22 | { 23 | int temp = n%10; 24 | if(temp == 0) 25 | { 26 | answer += 5 * pow(10,i); 27 | } 28 | i++; 29 | n = n/10; 30 | } 31 | return answer; 32 | } 33 | -------------------------------------------------------------------------------- /Geeks4Geeks/Misc/Rotate_Array.py: -------------------------------------------------------------------------------- 1 | test = int(input()) 2 | while test > 0 : 3 | n,rot = map(int,input().split()) 4 | l = list(map(int,input().split())) 5 | l = l[rot:] + l[:rot] 6 | for i in range(n) : 7 | print (l[i],end = " ") 8 | print() 9 | test -= 1 10 | -------------------------------------------------------------------------------- /Geeks4Geeks/Stacks/1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | void showstack(stack s) 6 | { 7 | while(!s.empty()) 8 | { 9 | cout << '\t' << s.top(); 10 | s.pop(); 11 | } 12 | } 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | int main() 21 | { 22 | stack s; 23 | s.push(10); 24 | s.push(30); 25 | s.push(20); 26 | s.push(5); 27 | s.push(1); 28 | 29 | cout << "The stack is : "; 30 | showstack(s); 31 | 32 | cout << "\ns.size() : " << s.size(); 33 | cout << "\ns.top() : " << s.top(); 34 | 35 | cout << "\ns.pop() : "; 36 | s.pop(); 37 | showstack(s); 38 | 39 | return 0; 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Geeks4Geeks/Stacks/Pairwise_Consecutive_Elements.cpp: -------------------------------------------------------------------------------- 1 | 2 | bool pairWiseConsecutive(stack s) 3 | { 4 | //Code here 5 | stack aux; 6 | int aux_size=0; 7 | while (!s.empty()) { 8 | aux.push(s.top()); 9 | s.pop(); 10 | aux_size++; 11 | } 12 | bool result = true; 13 | while (aux_size>1) { 14 | int x = aux.top(); 15 | aux.pop(); 16 | int y = aux.top(); 17 | aux.pop(); 18 | if (abs(x - y) != 1)result = false; 19 | s.push(x); 20 | s.push(y); 21 | aux_size--; 22 | aux_size--; 23 | } 24 | if (aux.size() == 1) 25 | s.push(aux.top()); 26 | return result; 27 | } 28 | -------------------------------------------------------------------------------- /Geeks4Geeks/Stacks/Remove_Repeated_Digits.py: -------------------------------------------------------------------------------- 1 | test = int(input()) 2 | while test > 0 : 3 | str1 = input() 4 | str1 = list(str1) 5 | l = [] 6 | l.append(str1[0]) 7 | for i in range(1,len(str1)) : 8 | if str1[i] != l[-1] : 9 | l.append(str1[i]) 10 | 11 | print(''.join(map(str,l))) 12 | test -= 1 13 | -------------------------------------------------------------------------------- /Geeks4Geeks/Stacks/Reverse_A_String.cpp: -------------------------------------------------------------------------------- 1 | void reverse(char *str, int len); 2 | int main() 3 | { 4 | long long int t; 5 | cin>>t; 6 | while(t--) 7 | { 8 | char str[10000]; 9 | cin>>str; 10 | long long int len=strlen(str); 11 | reverse(str,len); 12 | cout< s; 22 | for(int i = 0;i < len;i++) 23 | { 24 | s.push(str[i]); 25 | } 26 | int m = 0; 27 | while(!s.empty()) 28 | { 29 | str[m] = s.top(); 30 | s.pop(); 31 | m++; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /HackerEarth/Algorithms/Bubble Sort/Easy_Going.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | test = int(input()) 3 | while test > 0 : 4 | n,m = [int(x) for x in input().split()] 5 | l = list(map(int,input().split())) 6 | for i in range(n - 1) : 7 | for j in range(n - i - 1) : 8 | if l[j] > l[j+1] : 9 | l[j],l[j+1] = l[j+1],l[j] 10 | 11 | minsum = sum(l[:n-m]) 12 | l = l[::-1] 13 | maxsum = sum(l[:n-m]) 14 | print(maxsum - minsum) 15 | test -= 1 16 | -------------------------------------------------------------------------------- /HackerEarth/Algorithms/Bubble Sort/Shubam_And_XOR.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | from collections import Counter 3 | 4 | n = int(input()) 5 | l = list(map(int,input().split())) 6 | 7 | d = Counter(l) 8 | count = 0 9 | for key,value in d.items() : 10 | if value > 1 : 11 | count += (value * (value - 1))/2 12 | 13 | print ("%.f"%count) 14 | -------------------------------------------------------------------------------- /HackerEarth/Algorithms/Insertion Sort/The_Rise_Of_Wierd_Things.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | n = int(input()) 3 | l = list(map(int,input().split())) 4 | odd = [] 5 | even = [] 6 | for i in range(n) : 7 | if(l[i] % 2 == 0) : 8 | even.append(l[i]) 9 | else : 10 | odd.append(l[i]) 11 | 12 | odd.sort() 13 | even.sort() 14 | 15 | for i in even : 16 | print(i,end = " ") 17 | print(sum(even),end = " ") 18 | 19 | 20 | for i in odd : 21 | print(i,end = " ") 22 | print(sum(odd),end = " ") 23 | -------------------------------------------------------------------------------- /HackerEarth/Algorithms/Linear_Search/Min-Max.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | n = int(input()) 3 | l = list(map(int,input().split())) 4 | 5 | l.sort() 6 | minsum = sum(l[:n-1]) 7 | l = l[::-1] 8 | maxsum = sum(l[:n-1]) 9 | print(minsum,maxsum,sep= " ") 10 | -------------------------------------------------------------------------------- /HackerEarth/Algorithms/Linear_Search/Monk_Takes_A_Walk.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | test = int(input()) 3 | while test > 0 : 4 | n = input() 5 | count = 0 6 | l = ['a','e','i','o','u','A','E','I','O','U'] 7 | for i in n : 8 | if i in l : 9 | count += 1 10 | print(count) 11 | test -= 1 12 | -------------------------------------------------------------------------------- /HackerEarth/Algorithms/Linear_Search/Simple_Search.c: -------------------------------------------------------------------------------- 1 | // Write your code here 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int n; 8 | scanf("%d",&n); 9 | int i = 0; 10 | int arr[n]; 11 | for(i = 0;i < n;i++) 12 | { 13 | scanf("%d",&arr[i]); 14 | } 15 | int x; 16 | scanf("%d",&x); 17 | for(i = 0;i < n;i++) 18 | { 19 | if(arr[i] == x) 20 | { 21 | printf("%d",i); 22 | break; 23 | } 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/Achhe_Din.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | from collections import Counter 3 | test = int(input()) 4 | while test > 0 : 5 | n = int(input()) 6 | l = input().split() 7 | rogue = Counter(l) 8 | a = set(l) 9 | for i in a : 10 | if(rogue[i] != 3) : 11 | print (i) 12 | 13 | test -= 1 14 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/Anshul_Usama_And_Punishment.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | l = [20,30] 3 | count = 0 4 | i = 0 5 | while count < 20 : 6 | if len(l)%2 == 0 : 7 | l.append(l[i] * 2) 8 | else : 9 | l.append(l[i] * 3) 10 | i += 1 11 | count += 1 12 | n = int(input()) 13 | max1 = 0 14 | for i in range(n-1) : 15 | for j in range(i + 1,n) : 16 | if (abs(l[i] + l[j]) + abs(l[i] - l[j]) > max1) : 17 | max1 = abs(l[i] + l[j]) + abs(l[i] - l[j]) 18 | #print (l) 19 | print (max1) 20 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/Array_Game.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | n,m = [int(x) for x in input().split()] 3 | a = list(map(int,input().split())) 4 | b = list(map(int,input().split())) 5 | a.sort() 6 | b.sort() 7 | count = 0 8 | i,j = 0,m-1 9 | while(i=0): 10 | if(a[i] < b[j]): 11 | count += abs(a[i]-b[j]) 12 | i+=1; 13 | j-=1; 14 | print(count) 15 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/DedicationLevel.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | n = int(input()) 3 | d = {} 4 | while n > 0 : 5 | a,m = input().split() 6 | d[a] = int(m) 7 | n -= 1 8 | 9 | res = {key: val for key, val in sorted(d.items(), key = lambda ele: ele[1], reverse = True)} 10 | 11 | x = list(res.items()) 12 | for i in range(3): 13 | print(x[i][0]) 14 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/Hamiltonian_And_Lagrangian.c: -------------------------------------------------------------------------------- 1 | // Write your code here 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int n ; 8 | scanf("%d",&n); 9 | int i = 0; 10 | int arr[n]; 11 | for(i = 0;i < n;i++) 12 | { 13 | scanf("%d",&arr[i]); 14 | } 15 | int j = 0; 16 | int count = 0; 17 | for(i = 0;i < n;i++) 18 | { 19 | count = 0; 20 | for(j = i + 1;j < n;j++) 21 | { 22 | if(arr[i] >= arr[j]) 23 | { 24 | count ++; 25 | } 26 | else 27 | { 28 | break; 29 | } 30 | } 31 | if (count == n - i - 1) 32 | { 33 | printf("%d ",arr[i]); 34 | } 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/Help_Jarvis.py: -------------------------------------------------------------------------------- 1 | test = int(input()) 2 | while test > 0 : 3 | coaches = input() 4 | coach = [] 5 | for i in coaches : 6 | coach.append(int(i)) 7 | coach.sort() 8 | #print (coach) 9 | i = 0 10 | for i in range(0,len(coach)-1) : 11 | if (coach[i]) + 1 != (coach[i+1]) : 12 | break 13 | else : 14 | i += 1 15 | 16 | #print (i) 17 | if i == (len(coach) -1) : 18 | print ("YES") 19 | else : 20 | print ("NO") 21 | test -= 1 22 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/LAL_Evaluation.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int n,k; 7 | scanf("%d%d",&n,&k); 8 | int count = 0; 9 | int arr[n]; 10 | for(int i = 0;i < n;i++) 11 | { 12 | scanf("%d",&arr[i]); 13 | } 14 | for(int i = 0;i < n - 1;i++) 15 | { 16 | for(int j = i + 1;j < n;j++) 17 | { 18 | if(arr[i] + arr[j] == k) 19 | { 20 | count += 1; 21 | } 22 | } 23 | } 24 | printf("%d",count); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/Long_ATM_Queue.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | n = int(input()) 3 | arr = list(map(int,input().split())) 4 | group = 0 5 | for i in range(n-1) : 6 | if arr[i] > arr[i + 1] : 7 | group += 1 8 | 9 | print(group + 1) 10 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/MarkTheAnswer.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | n,x = input().split() 3 | n = int(n) 4 | x = int(x) 5 | l = list(map(int,input().split())) 6 | 7 | count = 0 8 | flag = 0 9 | for i in l: 10 | if i <= x : 11 | count += 1 12 | else : 13 | flag += 1 14 | if flag == 2: 15 | break 16 | 17 | print(count) 18 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/Maximize_The_Earning.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int s; 7 | scanf("%d",&s); 8 | while(s > 0) 9 | { 10 | int n,r; 11 | scanf("%d%d",&n,&r); 12 | int count = r; 13 | int build[n]; 14 | int i = 0; 15 | for(i = 0;i < n;i++) 16 | { 17 | scanf("%d",&build[i]); 18 | } 19 | i = 0; 20 | int j = 0; 21 | for(j = i + 1;j < n;j++) 22 | { 23 | if(build[j] > build[i]) 24 | { 25 | i = j; 26 | count += r; 27 | } 28 | } 29 | printf("%d\n",count); 30 | s --; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/Maximum_Of_K_Size_Subarrays.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | n,k = input().split() 3 | n = int(n) 4 | k = int(k) 5 | 6 | l = list(map(int,input().split())) 7 | i = 0 8 | 9 | while (i < n) : 10 | if (i + k < n + 1) : 11 | print(max(l[i:i + k]),end = " ") 12 | i += 1 13 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/Monk_And_Lucky_Minimum.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | test = int(input()) 3 | 4 | while test > 0 : 5 | n = int(input()) 6 | l = list(map(int,input().split())) 7 | count = 0 8 | mini = min(l) 9 | for i in l : 10 | if i == mini : 11 | count += 1 12 | if count%2 != 0 : 13 | print("Lucky") 14 | else : 15 | print("Unlucky") 16 | test -= 1 17 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/Monk_And_Welcome_Problem.c: -------------------------------------------------------------------------------- 1 | 2 | // Sample code to perform I/O: 3 | #include 4 | 5 | int main(){ 6 | int n; 7 | scanf("%d", &n); // Reading input from STDIN 8 | int a[n]; 9 | int b[n]; 10 | int c[n]; 11 | for(int i = 0;i < n;i++) 12 | { 13 | scanf("%d",&a[i]); 14 | } 15 | for(int i = 0;i < n;i++) 16 | { 17 | scanf("%d",&b[i]); 18 | } 19 | for(int i = 0;i < n;i++) 20 | { 21 | c[i] = a[i] + b[i]; 22 | printf("%d ",c[i]); 23 | } 24 | return 0; 25 | } 26 | 27 | // Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail 28 | 29 | 30 | // Write your code here 31 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/Most_Frequent.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | from collections import Counter 3 | n = int(input()) 4 | arr = list(map(int,input().split())) 5 | l = [] 6 | ctr = Counter(arr) 7 | m = max(ctr.values()) 8 | for i in ctr.keys(): 9 | if ctr[i] == m: 10 | l.append(i) 11 | print(min(l)) 12 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/Neutalisation_of_charges.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | s = input() 3 | 4 | l = list(s) 5 | new = [] 6 | new.append(l[0]) 7 | for i in range(1,len(l)) : 8 | new.append(l[i]) 9 | try : 10 | if new[-1] and new[-2] : 11 | if new[-1] == new[-2] : 12 | new.pop() 13 | new.pop() 14 | except : 15 | pass 16 | 17 | print (len(new)) 18 | print(''.join(new)) 19 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/Pepper_And_Contiguous_Even_Subarray.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | while t: 3 | n = int(input()) 4 | re = input().split() 5 | m_len = 0 6 | stk = 0 7 | for i in re: 8 | if int(i)&1 == 0: 9 | stk += 1 10 | else: 11 | stk = 0 12 | if (stk >=1) and (stk > m_len): 13 | m_len = stk 14 | if m_len > 0: 15 | print(m_len) 16 | else: 17 | print("-1") 18 | t -= 1 19 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/Prasun_The_Detective.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | 3 | ''' 4 | import re 5 | 6 | 7 | mess1 = input() 8 | mess1 = re.sub(r"[^\w\s]", '', mess1) 9 | mess1 = mess1.replace(" ",'') 10 | mess2 = input().replace(" ",'') 11 | mess2 = re.sub(r"[^\w\s]",'', mess2) 12 | 13 | if(set(mess1).issubset(set(mess2))==True): 14 | print ("YES") 15 | else : 16 | print ("NO") 17 | ''' 18 | 19 | mess=input() 20 | mesr=input() 21 | mess=mess.lower() 22 | mesr=mesr.lower() 23 | 24 | if(set(mesr).issubset(set(mess))==True): 25 | print("YES") 26 | else: 27 | print("NO") 28 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/R-r-riddikulus.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | n,r = [int(x) for x in input().split()] 3 | l = list(map(int,input().split())) 4 | while r > 0 : 5 | l = l[1:n] + l[0:1] 6 | r -= 1 7 | for i in l : 8 | print(i,end = " ") 9 | -------------------------------------------------------------------------------- /HackerEarth/Array1D/Reverse_An_Array.c: -------------------------------------------------------------------------------- 1 | 2 | // Sample code to perform I/O: 3 | #include 4 | 5 | int main(){ 6 | int num; 7 | scanf("%d", &num); // Reading input from STDIN 8 | int arr[num]; 9 | for(int i = 0;i < num;i++) 10 | { 11 | scanf("%d",&arr[i]); 12 | } 13 | for(int i = num - 1;i >= 0;i--) 14 | { 15 | printf("%d\n",arr[i]); 16 | } 17 | return 0; // Writing output to STDOUT 18 | } 19 | 20 | // Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail 21 | 22 | // Write your code here 23 | -------------------------------------------------------------------------------- /HackerEarth/Basics/Bit Manipulation/The_Castle_Gate.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Write your code here 5 | int main() 6 | { 7 | int test; 8 | cin >> test; 9 | while(test) 10 | { 11 | int n; 12 | cin >> n; 13 | int count = 0; 14 | for(int i = 1; i 3 | #include 4 | #include 5 | 6 | 7 | int main() 8 | { 9 | int n; 10 | scanf("%d",&n); 11 | int i = 0; 12 | double arr[n]; 13 | double answer = 1; 14 | for(i = 0;i < n;i++) 15 | { 16 | scanf("%lf",&arr[i]); 17 | answer = fmod((answer * arr[i]),(pow(10,9) + 7)); 18 | } 19 | printf("%.lf",answer); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Ali_And_People.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | str1 = input() 3 | vowels = ["A","E","I","O","U","Y"] 4 | a = int(str1[1]) + int(str1[0]) 5 | b = int(str1[3]) + int(str1[4]) 6 | c = int(str1[4]) + int(str1[5]) 7 | d = int(str1[7]) + int(str1[8]) 8 | 9 | if(a%2 == 0 and b%2 == 0 and c%2 == 0 and d%2 == 0 and str1[2] not in vowels) : 10 | print("valid") 11 | else : 12 | print("invalid") 13 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Aman_And_Sharma.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | // Write your code here 6 | int main() 7 | { 8 | int n; 9 | int sum = 0; 10 | cin >> n; 11 | while(n) 12 | { 13 | int r,x; 14 | cin >> r >> x; 15 | int tof = (100*x*7)/(2*22*r); 16 | if(tof > 0) 17 | { 18 | sum += 1; 19 | } 20 | n--; 21 | } 22 | cout << sum << endl; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Arithmetic_Progression.py: -------------------------------------------------------------------------------- 1 | from math import ceil 2 | # Write your code here 3 | 4 | if __name__ == "__main__" : 5 | test = int(input()) 6 | while test > 0 : 7 | a,b,c = map(int,input().split()) 8 | print(int(ceil(abs((c-b)-(b-a))/2))) 9 | test -= 1 10 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Book_Of_Potion_Making.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | 3 | num = input() 4 | n = len(num) 5 | add = 0 6 | for i in range(n) : 7 | add += ((i+1)*int(num[i])) 8 | 9 | 10 | if add%11 == 0 : 11 | print("Legal ISBN") 12 | else : 13 | print("Illegal ISBN") 14 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Bricks_Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | // Write your code here 6 | int main() 7 | { 8 | int n; 9 | cin >> n; 10 | int x = n; 11 | for(int i = 0;i < n;i++) 12 | { 13 | x -= i; 14 | if(x <= 0) 15 | { 16 | cout << "Patlu" << endl; 17 | break; 18 | } 19 | x -= i*2; 20 | if(x <= 0) 21 | { 22 | cout << "Motu" << endl; 23 | break; 24 | } 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Char_Sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | // Write your code here 6 | int main() 7 | { 8 | string s; 9 | cin >> s; 10 | int n = s.size(); 11 | int sum = 0; 12 | for(int i = 0;i < n;++i) 13 | { 14 | sum += (s[i] - 'a' + 1); 15 | } 16 | cout << sum << endl; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Cost_Of_Balloons.cpp: -------------------------------------------------------------------------------- 1 | // Sample code to perform I/O: 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | 8 | // Write your code here 9 | int main() 10 | { 11 | int test; 12 | cin >> test; 13 | while(test > 0) 14 | { 15 | int green,purple; 16 | int prob1 = 0; 17 | int prob2 = 0; 18 | cin >> green >> purple ; 19 | int peeps; 20 | cin >> peeps; 21 | while(peeps) 22 | { 23 | int first,second; 24 | cin >> first >> second; 25 | prob1 += first * 1; 26 | prob2 += second * 1; 27 | peeps --; 28 | } 29 | cout << min(green,purple) * max(prob1,prob2) + max(green,purple) * min(prob1,prob2) << endl; 30 | test --; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Count_Divisors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | 7 | int main() 8 | { 9 | int l,r,k; 10 | int count = 0; 11 | cin >> l >> r >> k; 12 | for(int i = l;i <= r;++i) 13 | { 14 | if(i%k == 0) 15 | { 16 | count += 1; 17 | } 18 | } 19 | cout << count << endl; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Divisibility.py: -------------------------------------------------------------------------------- 1 | N = int(input()) 2 | data = list(input().split()) 3 | 4 | result = "" 5 | for i in data : 6 | result += i[-1] 7 | 8 | if result[-1] == '0' : 9 | print("Yes") 10 | else : 11 | print("No") 12 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Doctors_Secret.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Write your code here 5 | int main() 6 | { 7 | int l,n; 8 | cin >> l >> n; 9 | if(l <= 23 && n >= 500 && n <= 1000) 10 | { 11 | cout << "Take Medicine" << endl; 12 | } 13 | else 14 | { 15 | cout << "Don't take Medicine" << endl; 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Duration.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | test = int(input()) 3 | while test > 0 : 4 | sh,sm,eh,em = map(int,input().split()) 5 | dur = (eh*60+em) - (sh*60+sm) 6 | print(dur//60,end=' ') 7 | print(dur%60) 8 | test -= 1 9 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/E_Maze.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | path = input() 3 | x = 0 4 | y = 0 5 | for i in path : 6 | if i == "L" : 7 | x -= 1 8 | elif i == "R" : 9 | x += 1 10 | elif i == "U" : 11 | y += 1 12 | else : 13 | y -= 1 14 | print(x,y) 15 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Factorial!.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int factorial(int num) 7 | { 8 | if(num == 0) return 1; 9 | return num * factorial(num-1); 10 | } 11 | 12 | 13 | // Write your code here 14 | int main() 15 | { 16 | int num; 17 | cin >> num; 18 | cout << factorial(num) << endl; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Hello.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | 4 | //import for Scanner and other utility classes 5 | import java.util.*; 6 | 7 | 8 | class TestClass { 9 | public static void main(String args[] ) throws Exception { 10 | 11 | //Scanner 12 | Scanner s = new Scanner(System.in); 13 | System.out.println("Hello Kirti"); 14 | 15 | // Write your code here 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/I_am_Easy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Write your code here 5 | int main() 6 | { 7 | int n; 8 | cin >> n; 9 | for(int i = 1;i <= 10;++i) 10 | { 11 | cout << i*n << endl; 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Ladderophilia.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | n = int(input()) 3 | print("* *") 4 | print("* *") 5 | while(n > 0) : 6 | print("*****") 7 | print("* *") 8 | print("* *") 9 | n -= 1 10 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Print_The_Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | // Write your code here 6 | int main() 7 | { 8 | int n; 9 | cin >> n; 10 | int temp; 11 | for(int i = 0;i < n;++i) 12 | { 13 | cin >> temp; 14 | cout << temp << " "; 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Roy_And_Profilepic.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void profile(int w,int h,int l) 6 | { 7 | if(w < l || h < l) 8 | { 9 | cout << "UPLOAD ANOTHER" << endl; 10 | } 11 | else if(w == h) 12 | { 13 | cout << "ACCEPTED" << endl; 14 | } 15 | else 16 | { 17 | cout << "CROP IT" << endl; 18 | } 19 | } 20 | 21 | 22 | 23 | // Write your code here 24 | int main() 25 | { 26 | int check; 27 | cin >> check; 28 | int test; 29 | cin >> test; 30 | while(test) 31 | { 32 | int width,height; 33 | cin >> width >> height; 34 | profile(width,height,check); 35 | test --; 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Teddy_And_Tweety.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | 4 | //import for Scanner and other utility classes 5 | import java.util.*; 6 | 7 | class TestClass { 8 | public static void main(String args[] ) throws Exception { 9 | //Scanner 10 | Scanner s = new Scanner(System.in); 11 | 12 | // Write your code here 13 | int num = Integer.valueOf(s.nextLine()); 14 | if(num%3 == 0 && (num/3 + num/3 + num/3 == num)) 15 | { 16 | System.out.print("YES"); 17 | } 18 | else 19 | { 20 | System.out.print("NO"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/Two_Strings.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | # Write your code here 3 | 4 | test = int(input()) 5 | while test > 0 : 6 | flag = 0 7 | a,b = input().split() 8 | strdict = defaultdict(int) 9 | for i in a : 10 | if i in strdict : 11 | strdict[i] += 1 12 | else : 13 | strdict[i] = 1 14 | for i in b : 15 | if i in strdict : 16 | strdict[i] -= 1 17 | else : 18 | strdict[i] = 1 19 | for i in strdict : 20 | if strdict[i] != 0 : 21 | flag = 1 22 | print("NO") 23 | break 24 | if flag == 0 : 25 | print("YES") 26 | test -= 1 27 | -------------------------------------------------------------------------------- /HackerEarth/Basics/IO/life_and_everthing.java: -------------------------------------------------------------------------------- 1 | //imports for BufferedReader 2 | import java.io.BufferedReader; 3 | import java.io.InputStreamReader; 4 | 5 | //import for Scanner and other utility classes 6 | import java.util.*; 7 | 8 | 9 | class TestClass { 10 | public static void main(String args[] ) throws Exception { 11 | 12 | //Scanner 13 | Scanner s = new Scanner(System.in); 14 | // Write your code here 15 | while(true) 16 | { 17 | int num = Integer.valueOf(s.nextLine()); 18 | if(num == 42) 19 | { 20 | break; 21 | } 22 | else 23 | { 24 | System.out.println(num); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /HackerEarth/Basics/Palindromic_String.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | n = input() 3 | if n == n[::-1] : 4 | print ("YES") 5 | else : 6 | print ("NO") 7 | -------------------------------------------------------------------------------- /HackerEarth/Basics/Prime_Number.c: -------------------------------------------------------------------------------- 1 | // Write your code here 2 | #include 3 | #include 4 | 5 | 6 | int main() 7 | { 8 | int n ; 9 | scanf("%d",&n); 10 | int count = 0; 11 | for(int i = 2;i < n;i++) 12 | { 13 | for(int j = 1;j < i;j++) 14 | { 15 | if(i % j == 0) 16 | { 17 | count ++ ; 18 | } 19 | } 20 | if(count == 1) 21 | { 22 | printf("%d ",i); 23 | } 24 | count = 0; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /HackerEarth/Basics/Zoos.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | n = input() 3 | counto = 0 4 | countz = 0 5 | for i in n : 6 | if i == 'o' : 7 | counto += 1 8 | else : 9 | countz += 1 10 | if counto == 2 * countz : 11 | print ("Yes") 12 | else : 13 | print ("No") 14 | -------------------------------------------------------------------------------- /HackerEarth/Contests/Codathon-MANIT/Day1.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | n,k = [int(x) for x in input().split()] 3 | l = [] 4 | while n > 0 : 5 | a = int(input()) 6 | l.append(a) 7 | n -= 1 8 | 9 | while(l[0] <= k) : 10 | l.pop(0) 11 | 12 | l = l[::-1] 13 | while (l[0] <= k) : 14 | l.pop(0) 15 | 16 | #print(l) 17 | print(len(l)) 18 | -------------------------------------------------------------------------------- /HackerEarth/Graphs/Gas_Stations.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | n,x = map(int,input().split()) 3 | l = list(map(int,input().split())) 4 | 5 | count = 0 6 | for i in l : 7 | if x > 0 : 8 | x -= i 9 | count += 1 10 | else : 11 | break 12 | 13 | print(count) 14 | -------------------------------------------------------------------------------- /HackerEarth/Graphs/Monk_Real_Estate.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | from collections import defaultdict 3 | 4 | 5 | class Graph: 6 | def __init__(self) : 7 | self.graph = defaultdict(list) 8 | 9 | 10 | def addEdge(self,v,w) : 11 | self.graph[v].append(w) 12 | self.graph[w].append(v) 13 | 14 | 15 | def noofcities(self) : 16 | count = 0 17 | for i in self.graph : 18 | count += 1 19 | return count 20 | 21 | 22 | if __name__ == "__main__": 23 | test = int(input()) 24 | while test > 0 : 25 | roads = int(input()) 26 | g = Graph() 27 | while roads > 0 : 28 | x,y = map(int,input().split()) 29 | g.addEdge(x,y) 30 | roads -= 1 31 | print(g.noofcities()) 32 | test -= 1 33 | -------------------------------------------------------------------------------- /HackerEarth/Greedy Algorithms/Coprimes.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | def __gcd(a, b): 3 | if (a == 0 or b == 0): return 0 4 | if (a == b): return a 5 | if (a > b): 6 | return __gcd(a - b, b) 7 | 8 | return __gcd(a, b - a) 9 | 10 | # Function to check and print if 11 | # two numbers are co-prime or not 12 | def coprime(a, b): 13 | 14 | if ( __gcd(a, b) == 1): 15 | return True 16 | else: 17 | return False 18 | 19 | 20 | n = int(input()) 21 | for i in range(n-2,-1,-1): 22 | if coprime(i,n): 23 | print(i) 24 | break 25 | -------------------------------------------------------------------------------- /HackerEarth/Hashing/Alien_Language.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | # Python 3 program to check if two 3 | # strings have common substring 4 | 5 | max_char = 26 6 | 7 | def twostrings(str1,str2) : 8 | v = [0] * (max_char) 9 | 10 | for i in range(len(str1)) : 11 | v[ord(str1[i]) - ord('a')] = True 12 | 13 | for i in range(len(str2)) : 14 | if v[ord(str2[i]) - ord('a')] : 15 | return True 16 | 17 | return False 18 | 19 | 20 | if __name__ == "__main__": 21 | test = int(input()) 22 | while test > 0 : 23 | str1 = input() 24 | str2 = input() 25 | if twostrings(str1,str2) : 26 | print("YES") 27 | else : 28 | print("NO") 29 | test -= 1 30 | -------------------------------------------------------------------------------- /HackerEarth/Hashing/All_Vowels.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | from collections import defaultdict 3 | n = int(input()) 4 | string = input() 5 | dict = defaultdict(int) 6 | 7 | for i in string : 8 | if i in dict : 9 | dict[i] += 1 10 | else : 11 | dict[i] = 1 12 | 13 | if dict['a'] >= 1 and dict['e'] >= 1 and dict['i'] >= 1 and dict['o'] >= 1 and dict['u'] >= 1 : 14 | print("YES") 15 | else : 16 | print("NO") 17 | -------------------------------------------------------------------------------- /HackerEarth/Hashing/Frequency_Of_Students.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | n = int(input()) 3 | dict = {} 4 | while n > 0 : 5 | name = input() 6 | if name in dict : 7 | dict[name] += 1 8 | else : 9 | dict[name] = 1 10 | n -= 1 11 | for key,value in sorted(dict.items()) : 12 | print(key,value) 13 | -------------------------------------------------------------------------------- /HackerEarth/Hashing/Jhool_And_Magical_Jewels.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | from collections import defaultdict 3 | 4 | test = int(input()) 5 | while test > 0 : 6 | string = input() 7 | n = len(string) 8 | dict = defaultdict(int) 9 | for i in string : 10 | if i in dict : 11 | dict[i] += 1 12 | else : 13 | dict[i] = 1 14 | minimum = min(dict['r'],dict['u'],dict['b'],dict['y']) 15 | print(minimum) 16 | test -= 1 17 | -------------------------------------------------------------------------------- /HackerEarth/Hashing/KK_crush.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | test = int(input()) 3 | while test > 0 : 4 | n = int(input()) 5 | l = list(map(int,input().split())) 6 | q = int(input()) 7 | while q > 0 : 8 | x = int(input()) 9 | if x in l : 10 | print("Yes") 11 | else : 12 | print("No") 13 | q -= 1 14 | test -= 1 15 | -------------------------------------------------------------------------------- /HackerEarth/Hashing/Maximum_Occurance.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | string = input() 3 | dict = {} 4 | 5 | maximum = 0 6 | 7 | for i in string : 8 | if i in dict : 9 | dict[i] += 1 10 | if dict[i] > maximum : 11 | maximum = dict[i] 12 | else : 13 | dict[i] = 1 14 | 15 | 16 | for key,value in sorted(dict.items()) : 17 | if value == maximum : 18 | print(str(key),str(value)) 19 | break 20 | 21 | #print(dict) 22 | -------------------------------------------------------------------------------- /HackerEarth/Hashing/Monk_And_Kundan.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | test = int(input()) 3 | hashing = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ" 4 | while test > 0 : 5 | l = list(map(str,input().split())) 6 | length = len(l) 7 | add = 0 8 | for i in l : 9 | for j in range(len(i)) : 10 | add += (j + hashing.find(i[j])) 11 | print(add*length) 12 | test -= 1 13 | -------------------------------------------------------------------------------- /HackerEarth/Hashing/N_Coordinates.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | import math 3 | import numpy as np 4 | import itertools 5 | 6 | if __name__ == "__main__": 7 | n = int(input()) 8 | l = [] 9 | while n > 0 : 10 | x,y = map(int,input().split()) 11 | l.append((x,y)) 12 | n -= 1 13 | dict = {} 14 | for i in l : 15 | if i in dict : 16 | dict[i] += 1 17 | else : 18 | dict[i] = 1 19 | 20 | for i,j in sorted(dict.items()) : 21 | print(i[0],i[1],j) 22 | 23 | """ 24 | for key,values in dict.items() : 25 | print(key[0],key[1],values) 26 | """ 27 | -------------------------------------------------------------------------------- /HackerEarth/Hashing/N_Coordinates_Pair.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | import math 3 | import numpy as np 4 | import itertools 5 | 6 | if __name__ == "__main__": 7 | n = int(input()) 8 | l = [] 9 | while n > 0 : 10 | x,y = map(int,input().split()) 11 | l.append((x,y)) 12 | n -= 1 13 | dict = {} 14 | for i in l : 15 | if i in dict : 16 | dict[i] += 1 17 | else : 18 | dict[i] = 1 19 | 20 | for i,j in sorted(dict.items()) : 21 | print(i[0],i[1],j) 22 | 23 | """ 24 | for key,values in dict.items() : 25 | print(key[0],key[1],values) 26 | """ 27 | -------------------------------------------------------------------------------- /HackerEarth/Hashing/Pair_Sums.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | import math 3 | import numpy as np 4 | import itertools 5 | import os 6 | from collections import defaultdict 7 | import re 8 | import sys 9 | import string 10 | 11 | def pairs(l,n,k) : 12 | dict = defaultdict(int) 13 | for i in l : 14 | if i in dict: 15 | dict[i] += 1 16 | else : 17 | dict[i] = 1 18 | count = 0 19 | for i in l : 20 | if k-i > 0 : 21 | count += dict[k-i] 22 | if k-i == i : 23 | count -= 1 24 | return count/2 25 | 26 | 27 | 28 | if __name__ == "__main__": 29 | n,k = map(int,input().split()) 30 | l = list(map(int,input().split())) 31 | flag = 0 32 | if pairs(l,n,k) : 33 | print("YES") 34 | else : 35 | print("NO") 36 | -------------------------------------------------------------------------------- /HackerEarth/Hashing/Xsquare_And_Doublestrings.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | import math 3 | import numpy as np 4 | import itertools 5 | import os 6 | import re 7 | import sys 8 | 9 | 10 | 11 | 12 | if __name__ == "__main__": 13 | test = int(input()) 14 | while test > 0 : 15 | flag = 0 16 | str1 = input() 17 | dict = {} 18 | for i in str1 : 19 | if i in dict : 20 | dict[i] += 1 21 | else : 22 | dict[i] = 1 23 | for key,value in dict.items() : 24 | if value > 1 : 25 | flag = 1 26 | print("Yes") 27 | break 28 | if flag == 0 : 29 | print("No") 30 | test -= 1 31 | -------------------------------------------------------------------------------- /HackerEarth/Hashing/Xsquare_And_Palindrome_Insertion.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | import math 3 | import numpy as np 4 | import itertools 5 | import os 6 | import re 7 | import sys 8 | 9 | 10 | if __name__ == "__main__": 11 | test = int(input()) 12 | while test > 0 : 13 | str1 = input() 14 | count = 0 15 | dict = {} 16 | for i in str1 : 17 | if i in dict : 18 | dict[i] += 1 19 | else : 20 | dict[i] = 1 21 | for key,value in dict.items() : 22 | if value%2 == 1 : 23 | count += 1 24 | if count == 0 : 25 | print(count) 26 | else : 27 | print(count - 1) 28 | test -= 1 29 | -------------------------------------------------------------------------------- /HackerEarth/Multi Dimensional Arrays/Alternate_Elements.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | from numpy import array 3 | 4 | l = list(map(int,input().split())) 5 | arr = array([l[:3],l[3:6],l[6:]]) 6 | #print(arr) 7 | print(arr[0][0] + arr[0][2] + arr[1][1] + arr[2][0] + arr[2][2]) 8 | print(arr[0][1] + arr[1][0] + arr[1][2] + arr[2][1]) 9 | -------------------------------------------------------------------------------- /HackerEarth/Multi Dimensional Arrays/Transpose.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | # Write your code here 3 | m,n = map(int,input().split()) 4 | l = [] 5 | while m > 0 : 6 | row = list(map(int,input().split())) 7 | l.append(row) 8 | m -= 1 9 | arr = np.array(l) 10 | arr = arr.T 11 | for i in arr : 12 | print(*i) 13 | -------------------------------------------------------------------------------- /HackerEarth/Polygon_Possible.py: -------------------------------------------------------------------------------- 1 | ''' 2 | test = int(input()) 3 | while test > 0 : 4 | n = int(input()) 5 | sides = list(map(int,input().split())) 6 | count = 0 7 | for i in sides : 8 | if sum(sides) - i > i : 9 | count += 1 10 | else : 11 | count += 0 12 | 13 | if count == len(sides) : 14 | print ("Yes") 15 | else : 16 | print ("No") 17 | 18 | test -= 1 19 | ''' 20 | T=int(input()) 21 | a=[] 22 | for i in range(T): 23 | n=int(input()) 24 | li=[int(i) for i in input().split()] 25 | a=sorted(li) 26 | b=max(li) 27 | c=a.pop() 28 | s=sum(a) 29 | if c 0 : 4 | q = int(input()) 5 | l = list(map(int,input().split())) 6 | p1 = [] 7 | for i in range(1,len(l)) : 8 | p1.append(l[i]) 9 | l2 = list(map(int,input().split())) 10 | for i in range(1,len(l2)) : 11 | p1.append(l2[i]) 12 | a = set(p1) 13 | if len(a) == q : 14 | print ("YES") 15 | else : 16 | print ("NO") 17 | test -= 1 18 | 19 | 20 | -------------------------------------------------------------------------------- /HackerEarth/Strange_Game.py: -------------------------------------------------------------------------------- 1 | # Write your code here 2 | test = int(input()) 3 | while test > 0 : 4 | n,k = [int(x) for x in input().split()] 5 | a = list(map(int,input().split())) 6 | b = list(map(int,input().split())) 7 | count = 0 8 | maxi = max(b) + 1 9 | for i in range(n) : 10 | if maxi >= a[i] : 11 | count += k * (maxi - a[i]) 12 | 13 | print(count) 14 | test -= 1 15 | -------------------------------------------------------------------------------- /LeetCode/Buy And Sell Stock2/Buy_And_Sell_Stock2.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProfit(vector& prices) { 4 | int n = prices.size(); 5 | int diff = 0; 6 | for(int i = 1;i < n;i++) 7 | { 8 | if(prices[i] > prices[i - 1]) 9 | { 10 | diff += prices[i] - prices[i - 1]; 11 | } 12 | } 13 | return diff; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /LeetCode/Container With Most Water/Container_With_Most_Water.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxArea(vector& height) 4 | { 5 | int maxarea = 0; 6 | int l = 0,r = height.size() - 1; 7 | while(l < r) 8 | { 9 | maxarea = max(maxarea,min(height[l],height[r]) * (r-l)); 10 | if(height[l] < height[r]) 11 | { 12 | l++; 13 | } 14 | else 15 | { 16 | r--; 17 | } 18 | } 19 | return maxarea; 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /LeetCode/Contiguous subarray/Contiguous_Subarray.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findMaxLength(self, nums: List[int]) -> int: 3 | nums=[nums[i] if nums[i]==1 else -1 for i in range(len(nums))] 4 | 5 | max_len=0 6 | cur_sum=0 7 | mapp={0:-1} 8 | 9 | for idx,v in enumerate(nums): 10 | cur_sum+=v 11 | if cur_sum in mapp: 12 | max_len=max(max_len,idx-mapp[cur_sum]) 13 | else: 14 | mapp[cur_sum]=idx 15 | 16 | return max_len 17 | -------------------------------------------------------------------------------- /LeetCode/Counting Elements/Counting_Elements.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countElements(self, arr: List[int]) -> int: 3 | arr.sort() 4 | c = Counter(arr) 5 | #print(arr) 6 | #print(c) 7 | setted = set(arr) 8 | setted = list(setted) 9 | #print(setted) 10 | count = 0 11 | for i in range(0,len(setted) - 1) : 12 | if setted[i] + 1 == setted[i+1] : 13 | count += c[setted[i]] 14 | return count 15 | -------------------------------------------------------------------------------- /LeetCode/Diameter BT/DiameterOfBinaryTree.py: -------------------------------------------------------------------------------- 1 | # Definition for a binary tree node. 2 | # class TreeNode: 3 | # def __init__(self, x): 4 | # self.val = x 5 | # self.left = None 6 | # self.right = None 7 | 8 | class Solution: 9 | def diameterOfBinaryTree(self, root: TreeNode) -> int: 10 | def dfs(node): 11 | if node is None: 12 | return 0 13 | left = dfs(node.left) 14 | right = dfs(node.right) 15 | self.ans = max(self.ans, left+right+1) 16 | return max(left, right)+1 17 | self.ans = 1 18 | dfs(root) 19 | return self.ans-1 20 | -------------------------------------------------------------------------------- /LeetCode/Even Digits/Even_Digits.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findNumbers(self, nums: List[int]) -> int: 3 | result = 0 4 | for i in nums : 5 | count = 0 6 | while i > 0 : 7 | count += 1 8 | i = i//10 9 | if count%2 == 0 : 10 | result += 1 11 | return result 12 | 13 | -------------------------------------------------------------------------------- /LeetCode/Group Anagrams/Group_Anagrams.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def groupAnagrams(self, strs: List[str]) -> List[List[str]]: 3 | result = [] 4 | _dict = {} 5 | for each in strs: 6 | each_sort = tuple(sorted(each)) 7 | if each_sort in _dict: 8 | _dict[each_sort].append(each) 9 | else: 10 | _dict[each_sort] = [each] 11 | for val in _dict.values(): 12 | result.append(val) 13 | return result 14 | -------------------------------------------------------------------------------- /LeetCode/Happy Number/Happy_Number.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | bool isHappy(int n) 5 | { 6 | while(n != 1 && n != 4) 7 | { 8 | n = squarenum(n); 9 | } 10 | if(n == 1) return true; 11 | else return false; 12 | } 13 | 14 | 15 | int squarenum(int n) 16 | { 17 | int rem = 0,sum = 0; 18 | while(n > 0) 19 | { 20 | rem = n%10; 21 | sum += (rem * rem); 22 | n = n/10; 23 | } 24 | return sum; 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /LeetCode/Jewels And Stones/Jewels_And_Stones.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numJewelsInStones(self, J: str, S: str) -> int: 3 | dict_j = {} 4 | count = 0 5 | dict_s = {} 6 | for i in J : 7 | if i in dict_j : 8 | dict_j[i] += 1 9 | else : 10 | dict_j[i] = 1 11 | for i in S : 12 | if i in dict_s : 13 | dict_s[i] += 1 14 | else : 15 | dict_s[i] = 1 16 | for i in dict_j.keys() : 17 | if i in dict_s.keys() : 18 | count += dict_s[i] 19 | #print(dict_j) 20 | #print(dict_s) 21 | return count 22 | 23 | -------------------------------------------------------------------------------- /LeetCode/Largest Sum Subarray/Largest_Sum_Subarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxSubArray(vector& nums) { 4 | int maxsofar = nums[0]; 5 | int maxendinghere = nums[0]; 6 | int n = nums.size(); 7 | 8 | for(int i = 1;i < n;i++) 9 | { 10 | maxendinghere = max(nums[i],maxendinghere + nums[i]); 11 | maxsofar = max(maxsofar,maxendinghere); 12 | } 13 | 14 | return maxsofar; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /LeetCode/Last Stone Weight/Last_Stone_Weight.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int lastStoneWeight(vector& stones) { 4 | priority_queue q; 5 | for (int s : stones) 6 | q.push(s); 7 | while (q.size() >= 2) { 8 | int a = q.top(); q.pop(); 9 | if (!q.empty()) { 10 | int b = q.top(); q.pop(); 11 | if (a != b) { 12 | q.push(abs(a - b)); 13 | } 14 | } 15 | } 16 | return q.empty() ? 0 : q.top(); 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /LeetCode/Linked List Middle/Middle_Of_Linked_List.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode(int x) : val(x), next(NULL) {} 7 | * }; 8 | */ 9 | class Solution { 10 | public: 11 | ListNode* middleNode(ListNode* head) 12 | { 13 | ListNode *fast = head; 14 | ListNode *slow = head; 15 | while (fast && fast->next) 16 | { 17 | fast = fast->next->next; 18 | slow = slow->next; 19 | } 20 | return slow; 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /LeetCode/Maximum Depth/Maximum_Depth.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * struct TreeNode { 4 | * int val; 5 | * TreeNode *left; 6 | * TreeNode *right; 7 | * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 | * }; 9 | */ 10 | class Solution { 11 | public: 12 | int maxDepth(TreeNode* root) { 13 | if(!root) return 0; 14 | else return max(maxDepth(root->left) + 1,maxDepth(root->right) + 1); 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /LeetCode/Move Zeroes/Move_Zeroes.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void moveZeroes(vector& nums) 4 | { 5 | int k = 0; 6 | int n = nums.size(); 7 | 8 | for(int i = 0;i < n;i++) 9 | { 10 | if(nums[i] != 0) 11 | { 12 | nums[k++] = nums[i]; 13 | } 14 | } 15 | 16 | for(int i = k;i < n;i++) 17 | { 18 | nums[k++] = 0; 19 | } 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /LeetCode/N Repeated Elements/N_Repeated_Elements: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def repeatedNTimes(self, A: List[int]) -> int: 3 | dict = {} 4 | size = len(A) 5 | for i in A : 6 | if i in dict : 7 | dict[i] += 1 8 | else : 9 | dict[i] = 1 10 | 11 | for i in dict.keys() : 12 | if dict[i] == size/2 : 13 | return i 14 | -------------------------------------------------------------------------------- /LeetCode/Palindrome_Number/Palindrome_Number.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def isPalindrome(self, x): 3 | """ 4 | :type x: int 5 | :rtype: bool 6 | """ 7 | 8 | return False if x < 0 else x == int(str(x)[::-1]) 9 | -------------------------------------------------------------------------------- /LeetCode/Palindrome_Number/Palindrome_nummber.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPalindrome(long long int x) { 4 | if(x < 0 || (x%10 == 0 && x != 0)) 5 | { 6 | return false; 7 | } 8 | 9 | int reverse = 0; 10 | while(x > reverse) 11 | { 12 | reverse = reverse * 10 + x%10; 13 | x = x /10; 14 | } 15 | 16 | return x == reverse || x == reverse/10; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /LeetCode/Product and Sum/Subtract_Product_And_Sum.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def subtractProductAndSum(self, n: int) -> int: 3 | x = n 4 | add = 0 5 | mul = 1 6 | while x > 0 : 7 | add += x%10 8 | mul *= x%10 9 | x = x//10 10 | return mul - add 11 | -------------------------------------------------------------------------------- /LeetCode/Reverse Linked List/Reverse_LL.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode(int x) : val(x), next(NULL) {} 7 | * }; 8 | */ 9 | class Solution { 10 | public: 11 | ListNode* reverseList(ListNode* head) { 12 | if(!head || !head->next) return head; 13 | 14 | ListNode * rest = reverseList(head->next); 15 | head->next->next = head; 16 | head->next = NULL; 17 | return rest; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /LeetCode/Reverse Linked List/Reverse_Linkedlist.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * struct ListNode *next; 6 | * }; 7 | */ 8 | 9 | 10 | struct ListNode* swapPairs(struct ListNode* head){ 11 | if(!head || !head->next) return head; 12 | 13 | struct ListNode * rem = head->next->next; 14 | struct ListNode * newhead = head->next; 15 | head->next->next = head; 16 | head->next = swapPairs(rem); 17 | return newhead; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /LeetCode/Reverse_Stringarray/Reverse_String.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseString(self, s: List[str]) -> None: 3 | """ 4 | Do not return anything, modify s in-place instead. 5 | """ 6 | n = len(s) 7 | for i in range(0,n//2) : 8 | s[i],s[n-i-1] = s[n-i-1],s[i] 9 | return s 10 | -------------------------------------------------------------------------------- /LeetCode/Reverse_Stringarray/Reverse_Stringarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int first = 0; 4 | void reverseString(vector& s) 5 | { 6 | if(!s.size()) return; 7 | if(first < s.size() - first - 1) 8 | { 9 | char temp = s[first]; 10 | s[first] = s[s.size() - first - 1]; 11 | s[s.size() - first - 1] = temp; 12 | first++; 13 | return reverseString(s); 14 | } 15 | else return; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /LeetCode/Running_Sum_1d/Running_Sum.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def runningSum(self, nums: List[int]) -> List[int]: 3 | n = len(nums) 4 | for i in range(1,n) : 5 | nums[i] += nums[i-1] 6 | return nums 7 | -------------------------------------------------------------------------------- /LeetCode/Shuffle The array/Array_Shuffle.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def shuffle(self, nums: List[int], n: int) -> List[int]: 3 | result = [] 4 | x = [i for i in nums[:n]] 5 | y = [i for i in nums[n:]] 6 | print(x,y) 7 | for i in range(n) : 8 | result.append(x[i]) 9 | result.append(y[i]) 10 | return result 11 | 12 | -------------------------------------------------------------------------------- /LeetCode/Single_Number/Single_Number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int singleNumber(vector& nums) { 4 | int n = nums.size(); 5 | int number = 0; 6 | for(int i = 0;i < n;i++) 7 | { 8 | number ^= nums[i]; 9 | } 10 | return number; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /LeetCode/String Shifts/Perform_String_Shifts.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def stringShift(self, s: str, shift: List[List[int]]) -> str: 3 | ns = collections.deque(s) 4 | for item in shift: 5 | if item[0] == 0: 6 | time = 0 7 | while time < item[1]: 8 | ns.append(ns.popleft()) 9 | time += 1 10 | else: 11 | time = 0 12 | while time < item[1]: 13 | ns.appendleft(ns.pop()) 14 | time += 1 15 | return ''.join(ns) 16 | 17 | -------------------------------------------------------------------------------- /LeetCode/Symmetric Tree/Symmetric_Tree.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * struct TreeNode { 4 | * int val; 5 | * TreeNode *left; 6 | * TreeNode *right; 7 | * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 | * }; 9 | */ 10 | class Solution { 11 | public: 12 | bool isSymmetric(TreeNode* root) { 13 | if(!root) return true; 14 | return ismirror(root,root); 15 | } 16 | 17 | 18 | bool ismirror(TreeNode * root1,TreeNode * root2) 19 | { 20 | if(!root1 && !root2) return true; 21 | 22 | if(!root1 || !root2) return false; 23 | 24 | if(root1->val != root2->val) return false; 25 | else 26 | return ismirror(root1->left,root2->right) && ismirror(root1->right,root2->left); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /LeetCode/Unique Number Of Occurances/Unique_Occurances.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def uniqueOccurrences(self, arr: List[int]) -> bool: 3 | dict = {} 4 | for i in arr : 5 | if i in dict : 6 | dict[i] += 1 7 | else : 8 | dict[i] = 1 9 | 10 | count = 0 11 | s = set(dict.values()) 12 | ns = len(s) 13 | nl = len(dict.values()) 14 | 15 | if nl != ns : 16 | return False 17 | else : 18 | return True 19 | -------------------------------------------------------------------------------- /Resources/Readme.md: -------------------------------------------------------------------------------- 1 | ## Some resources used by me : 2 | 3 | 1.https://medium.com/@andreimargeloiu/how-to-prepare-for-competitive-programming-396d557e0c12
4 | 2.https://www.geeksforgeeks.org/primality-test-set-1-introduction-and-school-method/
5 | 3.https://en.wikipedia.org/wiki/Primality_test
6 | -------------------------------------------------------------------------------- /SPOJ/Factorial.cpp: -------------------------------------------------------------------------------- 1 | //https://www.spoj.com/problems/FCTRL/ 2 | #include 3 | using namespace std ; 4 | #define ll long long 5 | 6 | 7 | ll zeroes(ll x) 8 | { 9 | ll mul = 5; 10 | ll zero = 0; 11 | while(x/mul > 0) 12 | { 13 | zero += x/mul; 14 | mul *= 5; 15 | } 16 | return zero; 17 | } 18 | 19 | 20 | 21 | int main() 22 | { 23 | ll test; 24 | cin >> test; 25 | while(test--) 26 | { 27 | ll x; 28 | cin >> x; 29 | cout << zeroes(x) << endl; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /SPOJ/Feynman.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | long long int square_sum(long long int n) 7 | { 8 | long long int sum = 0; 9 | for(int i = 1;i <= n;i++) 10 | { 11 | sum += i*i; 12 | } 13 | return sum; 14 | } 15 | 16 | 17 | 18 | int main() 19 | { 20 | while(true) 21 | { 22 | long long int n; 23 | scanf("%lld",&n); 24 | if(n == 0) break; 25 | else printf("%lld\n",square_sum(n)); 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /SPOJ/Small_Factorial.py: -------------------------------------------------------------------------------- 1 | //https://www.spoj.com/problems/FCTRL2/ 2 | def factorial(n) : 3 | if n == 1 : 4 | return 1 5 | else : 6 | return n * factorial(n - 1) 7 | 8 | 9 | 10 | 11 | if __name__ == "__main__" : 12 | test = int(input()) 13 | while test > 0 : 14 | n = int(input()) 15 | print(factorial(n)) 16 | test -= 1 17 | -------------------------------------------------------------------------------- /SPOJ/What's_Next.py: -------------------------------------------------------------------------------- 1 | while True : 2 | a,b,c = map(int,input().split()) 3 | if(a == 0 and b == 0 and c == 0) : 4 | break 5 | else : 6 | if(b - a == c - b) : 7 | print("AP",a + 3*(b - a),sep = " ") 8 | else : 9 | r = int(b/a) 10 | print("GP",a * r * r * r,sep = " ") 11 | -------------------------------------------------------------------------------- /SPOJ/bugs_life.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | void bugslife_spoj() 6 | { 7 | int t; cin >> t; 8 | for(int tc=1 ; tc<=t ;tc++){ 9 | int n,e; cin >> n>>e; 10 | rep(i ,0, n+1) 11 | { 12 | vis[i]=0; 13 | g[i].clear(); 14 | } 15 | rep(i , 0, e){ 16 | int u,v; cin >> u >> v; 17 | g[u].pb(v); g[v].pb(u); 18 | } 19 | int f=1; 20 | rep(i ,1 ,n+1){ 21 | if(!vis[i]){ 22 | bool res = dfs_bpg(i , 0); 23 | if(!res){ 24 | f=0;break; 25 | } 26 | } 27 | } 28 | cout << "Scenario #" << tc << ":" << endl; 29 | if(!f){ 30 | cout << "Suspicious bugs found!" << endl; 31 | } 32 | else cout << "No suspicious bugs found!" << endl; 33 | } 34 | } 35 | 36 | //driver code 37 | int32_t main(){ 38 | bugslife_spoj(); 39 | } 40 | -------------------------------------------------------------------------------- /SPOJ/fashion.py: -------------------------------------------------------------------------------- 1 | test = int(input()) 2 | while test > 0 : 3 | n = int(input()) 4 | men = list(map(int,input().split())) 5 | fem = list(map(int,input().split())) 6 | men.sort() 7 | fem.sort() 8 | hot = 0 9 | for i in range(n) : 10 | hot += men[i] * fem[i] 11 | print(hot) 12 | test -= 1 13 | -------------------------------------------------------------------------------- /SPOJ/life_and_everthing.cpp: -------------------------------------------------------------------------------- 1 | //https://www.spoj.com/problems/TEST/ 2 | //May the force be with you. 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | 8 | int main() 9 | { 10 | while(true) 11 | { 12 | int num; 13 | cin >> num; 14 | if(num == 42) break; 15 | cout << num << endl; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /SPOJ/prime1.py: -------------------------------------------------------------------------------- 1 | test = int(input()) 2 | while test > 0 : 3 | a,b = map(int,input().split()) 4 | sieve = [] 5 | for i in range(b + 1) : 6 | sieve.append(1) 7 | p = 2; 8 | while(p * p <= b) : 9 | if(sieve[p] == 1) : 10 | j = p * p 11 | while(j <= b) : 12 | sieve[j] = 0 13 | j += p 14 | p += 1 15 | for i in range(a,b + 1) : 16 | if sieve[i] == 1 and i != 1 : 17 | print(i) 18 | test -= 1 -------------------------------------------------------------------------------- /SPOJ/rectangles.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | long long int n; 8 | scanf("%lld",&n); 9 | long long int i,j; 10 | long long int rectangles = 0; 11 | for(i = 1;i <= n;i++) 12 | { 13 | for(j = i;j <= n;j++) 14 | { 15 | if(i * j <= n) rectangles ++; 16 | } 17 | } 18 | printf("%lld\n",rectangles); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Snippets/DSA_PROBLEMS/add_two_n_bit_integers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | int n ; 8 | scanf("%d",&n); 9 | int a[n]; 10 | int b[n]; 11 | for(int i = 0;i < n;i++) 12 | { 13 | scanf("%d",&a[i]); 14 | } 15 | for(int i = 0;i < n;i++) 16 | { 17 | scanf("%d",&b[i]); 18 | } 19 | int add[n + 1]; 20 | int carry = 0; 21 | int j = 0; 22 | for(j = n - 1;j >= 0;j--) 23 | { 24 | add[j + 1] = (a[j] + b[j] + carry)%2; 25 | carry = (a[j] + b[j] + carry)/2; 26 | } 27 | add[0] = carry; 28 | for(int k = 0;k < n + 1;k++) 29 | { 30 | printf("%d",add[k]); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Snippets/Search/linearsearch.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int n; 7 | scanf("%d",&n); 8 | int arr[n]; 9 | for(int i = 0;i < n;i++) 10 | { 11 | scanf("%d",&arr[i]); 12 | } 13 | int x; 14 | scanf("%d",&x); 15 | int j = 0; 16 | for(;j < n;j++) 17 | { 18 | if(arr[j] == x) 19 | { 20 | printf("%d",j); 21 | break; 22 | } 23 | } 24 | if(j > n) 25 | { 26 | printf("nil"); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Snippets/Sorting/Bubble_Sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | 6 | void swap(int *a,int *b) 7 | { 8 | int t = *a; 9 | *a = *b; 10 | *b = t; 11 | } 12 | 13 | 14 | 15 | 16 | int main() 17 | { 18 | int n; 19 | scanf("%d",&n); 20 | int arr[n]; 21 | int i = 0,j = 0; 22 | for(i = 0;i < n;i++) 23 | { 24 | scanf("%d",&arr[i]); 25 | } 26 | for(i = 0;i < n - 1;i++) 27 | { 28 | for(j = 0;j < n- i - 1;j++) 29 | { 30 | if(arr[j] > arr[j+1]) 31 | { 32 | swap(&arr[j],&arr[j+1]); 33 | } 34 | } 35 | } 36 | for(i = 0;i < n;i++) 37 | { 38 | printf("%d ",arr[i]); 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Snippets/Sorting/Bubble_Sort.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | l = list(map(int,input().split())) 3 | 4 | for i in range(n - 1) : 5 | for j in range(n - i - 1) : 6 | if l[j] > l[j + 1] : 7 | l[j],l[j+1] = l[j+1],l[j] 8 | 9 | for i in l : 10 | print(i,end = "") 11 | -------------------------------------------------------------------------------- /Snippets/Sorting/insertionsort.py: -------------------------------------------------------------------------------- 1 | def insertionsort(l,n) : 2 | for i in range(1,n) : # traverses through unsorted list 3 | temp = l[i] 4 | j = i - 1 5 | 6 | while(j >= 0 and l[j] > temp) : # swapping function 7 | l[j + 1] = l[j] 8 | j -= 1 9 | 10 | l[j + 1] = temp #puts the unsorted element in the correct position 11 | 12 | 13 | 14 | if __name__ == "__main__" : 15 | n = input("") 16 | l = [] 17 | for i in range(n) : 18 | a = input("") 19 | l.append(a) 20 | 21 | insertionsort(l,n) 22 | print l 23 | -------------------------------------------------------------------------------- /Snippets/String Functions/Strcpy: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void my_strcpy(char *s,char *t) 6 | { 7 | char *ptr = t; 8 | while(*s != '\0') 9 | { 10 | *t = *s; 11 | s++; 12 | t++; 13 | } 14 | printf("%s",ptr); 15 | } 16 | 17 | 18 | int main() 19 | { 20 | char *str1,*str2; 21 | str1 =(char *)malloc(256 * sizeof(char)); 22 | str2 =(char *)malloc(256 * sizeof(char)); 23 | scanf("%s",str1); 24 | my_strcpy(str1, str2); 25 | free(str1); 26 | free(str2); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Snippets/String Functions/strcat_C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void my_strcmp(char *s,char *t) 6 | { 7 | while(*s == *t) 8 | { 9 | if(*s == '\0' || *t == '\0') 10 | { 11 | break; 12 | } 13 | else 14 | { 15 | s++; 16 | t++; 17 | } 18 | } 19 | if(*s == '\0' && *t == '\0') 20 | { 21 | printf("0"); 22 | } 23 | else 24 | { 25 | printf("%d",abs(*s - *t)); 26 | } 27 | } 28 | 29 | 30 | int main() 31 | { 32 | char *str1,*str2; 33 | str1 =(char *)malloc(256 * sizeof(char)); 34 | str2 =(char *)malloc(256 * sizeof(char)); 35 | scanf("%s",str1); 36 | scanf("%s",str2); 37 | my_strcmp(str1, str2); 38 | free(str1); 39 | free(str2); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /UVa/ad-hoc/10082-WERTYU.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | 3 | keyboard = ['`','1','2','3','4','5','6','7','8','9','0','-','=','Q','W','E','R','T','Y','U','I','O','P','[',']',"\\",'A','S','D','F','G','H','J','K','L',';',"'",'Z','X','C','V','B','N','M',',','.','/'] 4 | 5 | while True: 6 | try: 7 | n = input() 8 | except EOFError: 9 | break 10 | # n = input() 11 | output = "" 12 | for i in n: 13 | if i == ' ' or i == 'Q' or i == 'A' or i == 'Z' or i == '`' or i == '\n': 14 | output += i 15 | else: 16 | output += keyboard[keyboard.index(i)-1] 17 | 18 | print(output) 19 | -------------------------------------------------------------------------------- /UVa/ad-hoc/10420-ListofConquests.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | dict = {} 3 | n = int(input()) 4 | for _ in range(n): 5 | country,name = input().split(maxsplit=1) 6 | # print(country + " name:" +name) 7 | if country not in dict: 8 | dict[country] = [name] 9 | else: 10 | if name not in dict[country]: 11 | dict[country] += [name] 12 | 13 | for country in sorted(dict): 14 | print(country + " " + str(len(dict[country]))) 15 | -------------------------------------------------------------------------------- /UVa/ad-hoc/10683-TheDecadaryWatch.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | while True: 3 | try: 4 | n = input() 5 | except EOFError: 6 | break 7 | 8 | 9 | normal = int(n[:2]) * 60 * 60 * 100 + int(n[2:4]) * 60 * 100 + int(n[4:6]) * 100 + int(n[6:]) 10 | decimalT = (normal * 10 * 100 * 100 * 100)//(24*60*60*100) 11 | print(str(decimalT).zfill(7)) 12 | -------------------------------------------------------------------------------- /UVa/ad-hoc/10812-BeatTheSpread.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | n = int(input()) 3 | for _ in range(n): 4 | s,d = map(int,input().split()) 5 | if s < d: 6 | print("impossible") 7 | else: 8 | a,b = 0,0 9 | a = (s+d)//2 10 | b = s - a 11 | 12 | if a >= 0 and b >= 0 and a + b == s and abs(a-b) == d: 13 | print(a,b) 14 | else: 15 | print("impossible") 16 | -------------------------------------------------------------------------------- /UVa/ad-hoc/11044-SearchingForNessy.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | n = int(input()) 3 | for _ in range(n): 4 | x,y = map(int,input().split()) 5 | print((x//3) * (y//3)) 6 | -------------------------------------------------------------------------------- /UVa/ad-hoc/11340-Newspaper.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | n = int(input()) 3 | for _ in range(n): 4 | x = int(input()) 5 | dict = {} 6 | for i in range(x): 7 | a,b = input().split() 8 | dict[a] = int(b) 9 | c = int(input()) 10 | cost = 0 11 | for j in range(c): 12 | y = input() 13 | cost += sum(map(lambda x: dict[x] if x in dict else 0, y)) 14 | 15 | print("{0:.2f}$".format(cost/100)) 16 | -------------------------------------------------------------------------------- /UVa/ad-hoc/11498-DivisionOfNlogonia.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | while True: 3 | n = int(input()) 4 | if n == 0: 5 | break 6 | x,y = map(int,input().split()) 7 | for _ in range(n) : 8 | a,b = map(int,input().split()) 9 | if a > x and b > y: 10 | print("NE") 11 | elif a < x and b < y: 12 | print("SO") 13 | elif a > x and b < y: 14 | print("SE") 15 | elif a < x and b > y: 16 | print("NO") 17 | elif a == x or b == y: 18 | print("divisa") 19 | -------------------------------------------------------------------------------- /UVa/ad-hoc/11547-AutomaticAnswer.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | n = int(input()) 3 | for i in range(n): 4 | x = int(input()) 5 | answer = (x * 567)//9 + 7492 6 | answer *= 235 7 | answer = answer//47 8 | answer -= 498 9 | answer = str(answer) 10 | print(answer[-2]) 11 | -------------------------------------------------------------------------------- /UVa/ad-hoc/11727-CostCutting.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | n = int(input()) 3 | for i in range(n): 4 | l = list(map(int,input().split())) 5 | l.sort() 6 | print("Case {}: {}".format(i+1,l[1])) 7 | 8 | -------------------------------------------------------------------------------- /UVa/ad-hoc/272-TEX_Quotes.py: -------------------------------------------------------------------------------- 1 | initial = True 2 | while(True): 3 | try : 4 | x = input() 5 | except EOFError: 6 | break 7 | 8 | output = [] 9 | for i in range(len(x)): 10 | if initial and x[i] == '"': 11 | output.append("``") 12 | initial = False 13 | elif initial == False and x[i] == '"': 14 | output.append("''") 15 | initial = True 16 | else: 17 | output.append(x[i]) 18 | 19 | print("".join(output)) 20 | print(x) 21 | #x = input() 22 | -------------------------------------------------------------------------------- /UVa/ad-hoc/483-Word_Scramble.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | while True: 3 | try: 4 | n = input() 5 | except: 6 | break 7 | 8 | n = n.split() 9 | output = [] 10 | for i in n: 11 | i = i[::-1] 12 | output.append(i) 13 | print(*output) 14 | # print() 15 | -------------------------------------------------------------------------------- /UVa/ad-hoc/941-Permutations.py: -------------------------------------------------------------------------------- 1 | from math import factorial 2 | 3 | fact_table = [factorial(i) for i in range(21)] 4 | num_tests = int(input()) 5 | 6 | for i in range(num_tests): 7 | text = str(input()) 8 | perm = int(input()) 9 | 10 | text = sorted(text) 11 | n = len(text) 12 | 13 | out = "" 14 | for i in reversed(range(n)): 15 | index, rem = divmod(perm, fact_table[i]) 16 | out += text[index] 17 | del text[index] 18 | perm = rem 19 | 20 | print(out) 21 | -------------------------------------------------------------------------------- /hackerrank/30 Days of Code/Day0.py: -------------------------------------------------------------------------------- 1 | # Read a full line of input from stdin and save it to our dynamically typed variable, input_string. 2 | input_string = input() 3 | 4 | # Print a string literal saying "Hello, World." to stdout. 5 | print('Hello, World.') 6 | 7 | # TODO: Write a line of code here that prints the contents of input_string to stdout. 8 | print(input_string) 9 | -------------------------------------------------------------------------------- /hackerrank/30 Days of Code/Day14.py: -------------------------------------------------------------------------------- 1 | class Difference: 2 | def __init__(self, a): 3 | self.__elements = a 4 | 5 | # Add your code here 6 | maximumDifference = -99999 7 | def computeDifference(self) : 8 | for i in self.__elements : 9 | for j in self.__elements : 10 | if abs(i-j) > self.maximumDifference : 11 | self.maximumDifference = abs(i-j) 12 | 13 | 14 | # End of Difference class 15 | 16 | _ = input() 17 | a = [int(e) for e in input().split(' ')] 18 | 19 | d = Difference(a) 20 | d.computeDifference() 21 | 22 | print(d.maximumDifference) 23 | -------------------------------------------------------------------------------- /hackerrank/30 Days of Code/Day16.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import sys 4 | 5 | S = input() 6 | try : 7 | print(int(S)) 8 | except ValueError : 9 | print("Bad String") 10 | -------------------------------------------------------------------------------- /hackerrank/30 Days of Code/Day19.py: -------------------------------------------------------------------------------- 1 | class AdvancedArithmetic(object): 2 | def divisorSum(n): 3 | raise NotImplementedError 4 | 5 | class Calculator(AdvancedArithmetic): 6 | def divisorSum(self, n): 7 | add = 0 8 | for i in range(1,n+1) : 9 | if n%i == 0 : 10 | add += i 11 | return add 12 | 13 | 14 | 15 | n = int(input()) 16 | my_calculator = Calculator() 17 | s = my_calculator.divisorSum(n) 18 | print("I implemented: " + type(my_calculator).__bases__[0].__name__) 19 | print(s) 20 | -------------------------------------------------------------------------------- /hackerrank/30 Days of Code/Day20.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import sys 4 | 5 | n = int(input().strip()) 6 | a = list(map(int, input().strip().split(' '))) 7 | # Write Your Code Here 8 | n = len(a) 9 | swaps = 0 10 | for i in range(0,n) : 11 | for j in range(0,n-i-1) : 12 | if a[j] > a[j+1] : 13 | a[j+1],a[j] = a[j],a[j+1] 14 | swaps += 1 15 | print("Array is sorted in " + str(swaps) + " swaps.") 16 | print("First Element:",str(a[0])) 17 | print("Last Element:",str(a[-1])) 18 | -------------------------------------------------------------------------------- /hackerrank/30 Days of Code/Day25.py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | import math 3 | 4 | 5 | def prime(n) : 6 | count = 0 7 | for i in range(1,math.ceil(math.sqrt(n))+1) : 8 | if n%i == 0: 9 | count += 1 10 | if count != 1 : 11 | print("Not prime") 12 | else : 13 | print("Prime") 14 | 15 | 16 | if __name__ == "__main__" : 17 | test = int(input()) 18 | while test > 0 : 19 | n = int(input()) 20 | if n == 2 or n==3 : 21 | print("Prime") 22 | elif n == 1 : 23 | print("Not prime") 24 | else : 25 | prime(n) 26 | test -= 1 27 | -------------------------------------------------------------------------------- /hackerrank/30 Days of Code/Day28.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | 11 | if __name__ == '__main__': 12 | N = int(input()) 13 | l = [] 14 | for N_itr in range(N): 15 | firstNameEmailID = input().split() 16 | firstName = firstNameEmailID[0] 17 | emailID = firstNameEmailID[1] 18 | if re.search(r"@gmail.com$",emailID) != None : 19 | l.append(firstName) 20 | l.sort() 21 | for i in l : 22 | print(i) 23 | -------------------------------------------------------------------------------- /hackerrank/30 Days of Code/Day29.py: -------------------------------------------------------------------------------- 1 | T = int(input().strip()) 2 | for _ in range(T): 3 | n , k = map(int , input().split()) 4 | print(k-1 if ((k-1) | k) <= n else k-2) 5 | -------------------------------------------------------------------------------- /hackerrank/30 Days of Code/Day6.py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | test = int(input()) 3 | while test > 0 : 4 | str1 = input() 5 | n = len(str1) 6 | for i in range(0,n,2) : 7 | if i != n-1 and i != n-2 : 8 | print(str1[i],end = "") 9 | if i == n-1 or i == n-2 : 10 | print(str1[i],end = " ") 11 | for i in range(1,n,2) : 12 | print(str1[i],end = "") 13 | print() 14 | test -= 1 15 | -------------------------------------------------------------------------------- /hackerrank/30 Days of Code/Day8.py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | from sys import stdin 3 | 4 | dict = {} 5 | 6 | test = int(input()) 7 | while test > 0 : 8 | name,val = input().split() 9 | dict[name] = val 10 | test -= 1 11 | 12 | lines = stdin.read().splitlines() 13 | for line in lines : 14 | if line in dict : 15 | print(line+"="+dict[line]) 16 | else : 17 | print("Not found") 18 | -------------------------------------------------------------------------------- /hackerrank/Data Structures/Arrays-DS.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # Complete the reverseArray function below. 10 | def reverseArray(a): 11 | a = a[::-1] 12 | return a 13 | 14 | if __name__ == '__main__': 15 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 16 | 17 | arr_count = int(input()) 18 | 19 | arr = list(map(int, input().rstrip().split())) 20 | 21 | res = reverseArray(arr) 22 | 23 | fptr.write(' '.join(map(str, res))) 24 | fptr.write('\n') 25 | 26 | fptr.close() 27 | -------------------------------------------------------------------------------- /hackerrank/Data Structures/Stacks/Equal_Stacks.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import os 4 | import sys 5 | 6 | 7 | n1,n2,n3 = map(int,input().split()) 8 | l1 = list(map(int,input().split())) 9 | l2 = list(map(int,input().split())) 10 | l3 = list(map(int,input().split())) 11 | 12 | l1 = l1[::-1] 13 | l2 = l2[::-1] 14 | l3 = l3[::-1] 15 | 16 | sum1 = sum(l1) 17 | sum2 = sum(l2) 18 | sum3 = sum(l3) 19 | 20 | while((sum1 != sum2 or sum2 != sum3 or sum1 != sum3)) : 21 | if(sum1 == 0 or sum2 == 0 or sum3 == 0) : 22 | sum1 = 0 23 | break 24 | 25 | elif(sum1 >= sum2 and sum1 >= sum3) : 26 | sum1 -= l1.pop() 27 | 28 | elif(sum2 >= sum3 and sum2 >= sum1) : 29 | sum2 -= l2.pop() 30 | 31 | elif(sum3 >= sum1 and sum3 >= sum2) : 32 | sum3 -= l3.pop() 33 | 34 | 35 | print(sum1) 36 | -------------------------------------------------------------------------------- /hackerrank/Java Language Proficiency/1DArray.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Solution { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scan = new Scanner(System.in); 8 | int n = scan.nextInt(); 9 | int[] a = new int[n]; 10 | for(int i = 0;i < n;++i) 11 | { 12 | a[i] = scan.nextInt(); 13 | } 14 | scan.close(); 15 | 16 | // Prints each sequential element in array a 17 | for (int i = 0; i < a.length; i++) { 18 | System.out.println(a[i]); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hackerrank/Java Language Proficiency/JavaInheritance.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | class Animal{ 8 | void walk(){ 9 | System.out.println("I am walking"); 10 | } 11 | } 12 | 13 | class Bird extends Animal{ 14 | void fly(){ 15 | System.out.println("I am flying"); 16 | } 17 | 18 | void sing(){ 19 | System.out.println("I am singing"); 20 | } 21 | } 22 | 23 | public class Solution{ 24 | 25 | public static void main(String args[]){ 26 | 27 | Bird bird = new Bird(); 28 | bird.walk(); 29 | bird.fly(); 30 | bird.sing(); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /hackerrank/Java Language Proficiency/JavaStringReverse.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Solution { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner sc=new Scanner(System.in); 9 | String A=sc.next(); 10 | /* Enter your code here. Print output to STDOUT. */ 11 | String revA = ""; 12 | for(int i = A.length() - 1;i >= 0;--i) 13 | { 14 | revA += A.charAt(i); 15 | } 16 | if(A.equals(revA)) 17 | { 18 | System.out.println("Yes"); 19 | } 20 | else 21 | { 22 | System.out.println("No"); 23 | } 24 | 25 | } 26 | } 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /hackerrank/Java Language Proficiency/Loops.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class Solution { 10 | 11 | 12 | 13 | private static final Scanner scanner = new Scanner(System.in); 14 | 15 | public static void main(String[] args) { 16 | int n = scanner.nextInt(); 17 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 18 | scanner.close(); 19 | 20 | for(int i = 1;i <= 10;++i) 21 | { 22 | System.out.println(n + " x " + i + " = " + (n*i)); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /hackerrank/Java Language Proficiency/StdinAndStdout.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Solution { 4 | 5 | public static void main(String[] args) { 6 | Scanner scan = new Scanner(System.in); 7 | int a = scan.nextInt(); 8 | // Complete this line 9 | int b = scan.nextInt(); 10 | // Complete this line 11 | int c = scan.nextInt(); 12 | 13 | System.out.println(a); 14 | // Complete this line 15 | System.out.println(b); 16 | // Complete this line 17 | System.out.println(c); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /hackerrank/Java Language Proficiency/StdinAndStdout2.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Solution { 4 | 5 | public static void main(String[] args) { 6 | Scanner scan = new Scanner(System.in); 7 | int i = scan.nextInt(); 8 | 9 | // Write your code here. 10 | double d = scan.nextDouble(); 11 | scan.nextLine(); 12 | String s = scan.nextLine(); 13 | System.out.println("String: " + s); 14 | System.out.println("Double: " + d); 15 | System.out.println("Int: " + i); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /hackerrank/Java Language Proficiency/Substring.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | String S = in.next(); 12 | int start = in.nextInt(); 13 | int end = in.nextInt(); 14 | System.out.println(S.substring(start,end)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /hackerrank/Java Language Proficiency/WelcomeToJava.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | public static void main(String[] args) { 4 | /* Enter your code here. Print output to STDOUT. Your class should be named Solution. */ 5 | System.out.println("Hello, World."); 6 | System.out.println("Hello, Java."); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /hackerrank/Java Language Proficiency/abstractClasses.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | abstract class Book{ 3 | String title; 4 | abstract void setTitle(String s); 5 | String getTitle(){ 6 | return title; 7 | } 8 | } 9 | 10 | //Write MyBook class here 11 | class MyBook extends Book { 12 | public void setTitle(String s) { 13 | this.title = s; 14 | } 15 | } 16 | 17 | public class Main{ 18 | 19 | public static void main(String []args){ 20 | //Book new_novel=new Book(); This line prHMain.java:25: error: Book is abstract; cannot be instantiated 21 | Scanner sc=new Scanner(System.in); 22 | String title=sc.nextLine(); 23 | MyBook new_novel=new MyBook(); 24 | new_novel.setTitle(title); 25 | System.out.println("The title is: "+new_novel.getTitle()); 26 | sc.close(); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /hackerrank/Java Language Proficiency/superKeyword.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class BiCycle{ 5 | String define_me(){ 6 | return "a vehicle with pedals."; 7 | } 8 | } 9 | 10 | class MotorCycle extends BiCycle{ 11 | String define_me(){ 12 | return "a cycle with an engine."; 13 | } 14 | 15 | MotorCycle(){ 16 | System.out.println("Hello I am a motorcycle, I am "+ define_me()); 17 | 18 | String temp=super.define_me(); //Fix this line 19 | 20 | System.out.println("My ancestor is a cycle who is "+ temp ); 21 | } 22 | 23 | } 24 | class Solution{ 25 | public static void main(String []args){ 26 | MotorCycle M=new MotorCycle(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/Capitalize!.py: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # Complete the solve function below. 11 | def solve(s): 12 | for x in s[:].split(): 13 | s = s.replace(x, x.capitalize()) 14 | return s 15 | 16 | 17 | 18 | if __name__ == '__main__': 19 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 20 | 21 | s = raw_input() 22 | 23 | result = solve(s) 24 | 25 | fptr.write(result + '\n') 26 | 27 | fptr.close() 28 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/Counter.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | # Enter your code here. Read input from STDIN. Print output to STDOUT 3 | 4 | x = int(input()) 5 | size = list(map(int,input().split())) 6 | dict = Counter(size) 7 | n = int(input()) 8 | profit = 0 9 | 10 | 11 | while n > 0 : 12 | size,price = map(int,input().split()) 13 | if dict[size] > 0 : 14 | dict[size] -= 1 15 | profit += price 16 | n -= 1 17 | 18 | print(profit) 19 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/Designer_Door_Mat.py: -------------------------------------------------------------------------------- 1 | x,y = map(int,input("").split()) 2 | for i in range(1,int(x/2) + 1) : 3 | for j in range(0,(int(x/2)-i + 1)*3) : 4 | print("-",end="") 5 | #print(" ",end = "") 6 | for k in range(2*i-1) : 7 | print(".|.",end = "") 8 | for j in range(0,(int(x/2)-i+ 1)*3) : 9 | print("-",end="") 10 | print() 11 | print("-" * int((y-7)/2) + "WELCOME" + "-" * int((y-7)/2)) 12 | for i in range(1,int(x/2)+1) : 13 | for j in range(i*3) : 14 | print("-",end = "") 15 | #print(" ",end = "") 16 | for k in range(2*(int(x/2)-i + 1)-1) : 17 | print(".|.",end = "") 18 | for j in range(i*3) : 19 | print("-",end = "") 20 | print () 21 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/Exceptions.py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | test = input("") 3 | while test > 0 : 4 | a,b = raw_input("").split(" ") 5 | try : 6 | a = int(a) 7 | b = int(b) 8 | print (a/b) 9 | except ZeroDivisionError as e : 10 | print "Error Code: " + str(e) 11 | except ValueError as e : 12 | print "Error Code: " + str(e) 13 | test -= 1 14 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/FindAString_Python: -------------------------------------------------------------------------------- 1 | def count_substring(string,substring): 2 | count = 0 3 | for i in range(len(string)): 4 | if(string[i:i + len(substring)] == substring): 5 | count += 1 6 | return count 7 | 8 | if __name__ == '__main__': 9 | string = raw_input().strip() 10 | sub_string = raw_input().strip() 11 | 12 | count = count_substring(string, sub_string) 13 | print count 14 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/Find_Angle_MBC.py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | import math 3 | AB = float(input()) 4 | BC = float(input()) 5 | 6 | print(str(int(round(math.degrees(math.atan2(AB, BC)))))+'°') 7 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/Finding_The_Percentage.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | n = int(input("")) 3 | al =[] 4 | while(n > 0) : 5 | l = input().split() 6 | al.append(l) 7 | n -= 1 8 | sum = 0 9 | name = input("") 10 | for i in al : 11 | if i[0] == name : 12 | for j in range(1,4) : 13 | sum += float(i[j]) 14 | print("{:.2f}".format(sum/3.00)) 15 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/Lists.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | N = int(raw_input()) 3 | l = [] 4 | while N > 0 : 5 | a = raw_input("").split(" ") 6 | if a[0] == 'insert' : 7 | l.insert(int(a[1]),int(a[2])) 8 | 9 | elif a[0] == 'print' : 10 | print l 11 | 12 | elif a[0] == 'remove' : 13 | l.remove(int(a[1])) 14 | 15 | elif a[0] == 'append' : 16 | l.append(int(a[1])) 17 | 18 | elif a[0] == 'sort' : 19 | l.sort() 20 | 21 | elif a[0] == 'pop' : 22 | l.pop() 23 | 24 | else : 25 | l.reverse() 26 | 27 | 28 | N -= 1 29 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/Merge_The_Tools.py: -------------------------------------------------------------------------------- 1 | def merge_the_tools(string, k): 2 | # your code goes here 3 | n = len(string) 4 | l = [dict.fromkeys(string[0+i:k+i]) for i in range(0, n, k)] 5 | for i in l : 6 | print("".join(i)) 7 | 8 | if __name__ == '__main__': 9 | string, k = input(), int(input()) 10 | merge_the_tools(string, k) 11 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/Mutations_Python: -------------------------------------------------------------------------------- 1 | def mutate_string(string, position, character): 2 | string = string[:position] + character + string[position + 1:] 3 | return string 4 | 5 | if __name__ == '__main__': 6 | s = raw_input() 7 | i, c = raw_input().split() 8 | s_new = mutate_string(s, int(i), c) 9 | print s_new 10 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/Sets.py: -------------------------------------------------------------------------------- 1 | def average(array): 2 | # your code goes here 3 | s = list(set(array)) 4 | summation = sum(s) 5 | return (summation/len(s)) 6 | 7 | if __name__ == '__main__': 8 | n = int(input()) 9 | arr = list(map(int, input().split())) 10 | result = average(arr) 11 | print(result) 12 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/String Split And Join_Python: -------------------------------------------------------------------------------- 1 | def split_and_join(line): 2 | # write your code here 3 | line = line.split(" ") 4 | line = "-".join(line) 5 | return line 6 | 7 | if __name__ == '__main__': 8 | line = raw_input() 9 | result = split_and_join(line) 10 | print result 11 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/String_Validators.py: -------------------------------------------------------------------------------- 1 | str = raw_input() 2 | print any(c.isalnum() for c in str) 3 | print any(c.isalpha() for c in str) 4 | print any(c.isdigit() for c in str) 5 | print any(c.islower() for c in str) 6 | print any(c.isupper() for c in str) 7 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/TextWrap.py: -------------------------------------------------------------------------------- 1 | import textwrap 2 | 3 | def wrap(string, max_width): 4 | result = textwrap.fill(string,max_width) 5 | return result 6 | 7 | if __name__ == '__main__': 8 | string, max_width = input(), int(input()) 9 | result = wrap(string, max_width) 10 | print(result) 11 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/The_Minion_Game.py: -------------------------------------------------------------------------------- 1 | def minion_game(string): 2 | # your code goes here 3 | #string = string.lower() 4 | vowel = ['A','E','I','O','U'] 5 | kev = 0 6 | stu = 0 7 | n = len(string) 8 | x = n 9 | for i in range(n) : 10 | if string[i] in vowel : 11 | kev += x 12 | else : 13 | stu += x 14 | x -= 1 15 | 16 | if kev > stu : 17 | print("Kevin",str(kev)) 18 | elif kev < stu : 19 | print("Stuart",str(stu)) 20 | else : 21 | print("Draw") 22 | 23 | 24 | if __name__ == '__main__': 25 | s = input() 26 | minion_game(s) 27 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/WordsScore_Python: -------------------------------------------------------------------------------- 1 | def is_vowel(letter): 2 | return letter in ['a', 'e', 'i', 'o', 'u', 'y'] 3 | 4 | def score_words(words): 5 | score = 0 6 | for word in words: 7 | num_vowels = 0 8 | for letter in word: 9 | if is_vowel(letter): 10 | num_vowels += 1 11 | if num_vowels % 2 == 0: 12 | score += 2 13 | else: 14 | score += 1 15 | return score 16 | 17 | 18 | n = int(raw_input()) 19 | words = raw_input().split() 20 | print score_words(words) 21 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/sWAP cASe_python: -------------------------------------------------------------------------------- 1 | def swap_case(s): 2 | a = "" 3 | for letter in s: 4 | if(letter.isupper() == True): 5 | a += letter.lower() 6 | else: 7 | a += letter.upper() 8 | return a 9 | 10 | if __name__ == '__main__': 11 | s = raw_input() 12 | result = swap_case(s) 13 | print result 14 | -------------------------------------------------------------------------------- /hackerrank/Python Language Proficiency/stringFormatting.py: -------------------------------------------------------------------------------- 1 | def print_formatted(number): 2 | # your code goes here 3 | binNumber = bin(number)[2:] 4 | 5 | 6 | for i in range(1,number+1): 7 | octalNum = oct(i)[2:] 8 | hexNum = hex(i)[2:].upper() 9 | binNum = bin(i)[2:] 10 | print("{} {} {} {}".format(str(i).rjust(len(binNumber),' '),octalNum.rjust(len(binNumber),' '),hexNum.rjust(len(binNumber),' '),binNum.rjust(len(binNumber),' '))) 11 | 12 | # oct(i)[2:].rjust(len(oct[number][2:]),' '),hex(i)[2:].rjust(len(hex(number),' ')),bin(i)[2:].rjust(len(bin(number)[2:]),' '))) 13 | 14 | if __name__ == '__main__': 15 | n = int(input()) 16 | print_formatted(n) 17 | -------------------------------------------------------------------------------- /hackerrank/c language proficiency/FunctionsInC_C: -------------------------------------------------------------------------------- 1 | #include 2 | int max_of_four(int a,int b,int c,int d){ 3 | int max; 4 | if(a>b&&a>c&&a>d){ 5 | max=a; 6 | } 7 | else if(b>a&&b>c&&b>d){ 8 | max=b; 9 | } 10 | else if(c>a&&c>b&&c>d){ 11 | max=c; 12 | } 13 | else if(d>a&&d>b&&d>c){ 14 | max=d; 15 | } 16 | return max; 17 | } 18 | 19 | int main() { 20 | int a, b, c, d; 21 | scanf("%d %d %d %d", &a, &b, &c, &d); 22 | int ans = max_of_four(a, b, c, d); 23 | printf("%d", ans); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /hackerrank/c language proficiency/HelloWorld_C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | 7 | char s[100]; 8 | scanf("%[^\n]%*c", &s); 9 | 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | printf("Hello, World!\n"); 12 | printf("Welcome to C programming."); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /hackerrank/c language proficiency/PlayingWithCharecters_C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | 9 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 10 | char ch; 11 | char s[100]; 12 | char sen[1000]; 13 | scanf("%c",&ch); 14 | scanf("%s",s); 15 | scanf(" %[^\n]%*c",&sen); 16 | printf("%c\n",ch); 17 | printf("%s\n",s); 18 | printf("%s",sen); 19 | return 0; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /hackerrank/c language proficiency/PointersInC_C: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int a,b,c,d; 4 | scanf("%d %d",&a,&b); 5 | c=a+b; 6 | printf("%d\n",c); 7 | if(a>b){ 8 | d=a-b; 9 | printf("%d",d); 10 | } 11 | else{ 12 | d=b-a; 13 | printf("%d",d); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /hackerrank/c language proficiency/PrintingNewTokens_C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | 8 | char *s; 9 | s = malloc(1024 * sizeof(char)); 10 | scanf("%[^\n]", s); 11 | s = realloc(s, strlen(s) + 1); 12 | //Write your logic to print the tokens of the sentence here. 13 | while(*s != '\0') 14 | { 15 | printf("%c",*s); 16 | if(*s == ' ') 17 | { 18 | printf("\n"); 19 | } 20 | s++; 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /hackerrank/c language proficiency/PrintingPattern_C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | 9 | int n; 10 | scanf("%d", &n); 11 | // Complete the code to print the pattern. 12 | int len = n*2 - 1; 13 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int a,b,e,f; 9 | float c,d,g,h; 10 | scanf("%d %d",&a,&b); 11 | scanf("%f %f",&c,&d); 12 | e=a+b; 13 | f=a-b; 14 | g=c+d; 15 | h=c-d; 16 | printf("%.1d %.1d\n",e,f); 17 | printf("%.1f %.1f\n",g,h); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /hackerrank/c language proficiency/for loop_c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | 8 | int main() 9 | { 10 | int a, b; 11 | scanf("%d\n%d", &a, &b); 12 | // Complete the code. 13 | 14 | char *num_arr[10] = {"one","two","three","four","five","six","seven","eight","nine"}; 15 | int i = 0; 16 | for(i = a;i <= b;i++) 17 | { 18 | if(i <= 9) 19 | { 20 | printf("%s",num_arr[i - 1]); 21 | } 22 | else 23 | { 24 | if(i % 2 == 0) 25 | { 26 | printf("even"); 27 | } 28 | else 29 | { 30 | printf("odd"); 31 | } 32 | } 33 | printf("\n"); 34 | } 35 | 36 | return 0; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /hackerrank/c++ language proficiency/ArraysIntroduction_CPP: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | 7 | int main() { 8 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 9 | int n; 10 | cin >> n; 11 | int i; 12 | int arr[n]; 13 | for(i = 0;i < n;i++) 14 | { 15 | scanf("%d ",&arr[i]); 16 | } 17 | for(i = n -1;i >= 0;i--) 18 | { 19 | printf("%d ",arr[i]); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /hackerrank/c++ language proficiency/ForLoop_CPP: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | // Complete the code. 7 | string num_array[] = {"one","two","three","four","five","six","seven","eight","nine"}; 8 | int a,b; 9 | scanf("%d\n%d",&a,&b); 10 | int i = 0; 11 | for(i = a;i <= b;i++) 12 | { 13 | if(i <= 9) 14 | { 15 | cout << num_array[i - 1] << '\n'; 16 | } 17 | else 18 | { 19 | if(i % 2 == 0) 20 | { 21 | printf("even\n"); 22 | } 23 | else 24 | { 25 | printf("odd\n"); 26 | } 27 | } 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /hackerrank/c++ language proficiency/Functions_CPP: -------------------------------------------------------------------------------- 1 | #include 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 max_of_four(int a,int b,int c,int d) 10 | { 11 | int max = 0; 12 | if(a > b && a > c && a > d) 13 | { 14 | max = a; 15 | } 16 | else if(b > a && b > c && b > d) 17 | { 18 | max = b; 19 | } 20 | else if(c > a && c > b && c > d) 21 | { 22 | max = c; 23 | } 24 | else 25 | { 26 | max = d; 27 | } 28 | return max; 29 | } 30 | 31 | int main() { 32 | int a, b, c, d; 33 | scanf("%d %d %d %d", &a, &b, &c, &d); 34 | int ans = max_of_four(a, b, c, d); 35 | printf("%d", ans); 36 | 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /hackerrank/c++ language proficiency/Pointers_CPP: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void update(int *a,int *b) { 5 | // Complete this function 6 | int temp = *a; 7 | *a = *a + *b; 8 | *b = abs(temp - *b); 9 | } 10 | 11 | int main() { 12 | int a, b; 13 | int *pa = &a, *pb = &b; 14 | 15 | scanf("%d %d", &a, &b); 16 | update(pa, pb); 17 | printf("%d\n%d", a, b); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /hackerrank/c++ language proficiency/Strings_CPP: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | string a, b; 8 | cin >> a >> b; 9 | 10 | cout << a.length() << ' ' << b.length() << endl; 11 | 12 | cout << a + b << endl; 13 | 14 | swap( a[0], b[0] ); 15 | cout << a << ' ' << b << endl; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /hackerrank/c++ language proficiency/data types: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | // Complete the code. 7 | int a; 8 | long b; 9 | char c; 10 | float d; 11 | double e; 12 | scanf("%d %ld %c %f %lf",&a,&b,&c,&d,&e); 13 | printf("%d\n%ld\n%c\n%f\n%lf\n",a,b,c,d,e); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/3Dsurfacearea.py: -------------------------------------------------------------------------------- 1 | HW = list(map(int, input().strip().split(' '))) 2 | import math 3 | H = HW[0] 4 | W = HW[1] 5 | sum = 0 6 | w=[] 7 | for i in range(H): 8 | a = list(map(int, input().strip().split(' '))) 9 | for x in a: 10 | sum = sum+x 11 | w.append(a) 12 | t = 6*sum 13 | for x in w: 14 | for y in x: 15 | t = t-2*(y-1) 16 | for i in range(H): 17 | for j in range(0,W-1): 18 | if w[i][j]>w[i][j+1]: 19 | t = t - 2*(w[i][j+1]) 20 | else: 21 | t=t-2*(w[i][j]) 22 | for j in range(W): 23 | for i in range(H-1): 24 | if w[i][j]>w[i+1][j]: 25 | t=t-2*(w[i+1][j]) 26 | else: 27 | t = t-2*(w[i][j]) 28 | print(t) 29 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/BirthdayChocalate.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int n; 9 | scanf("%d",&n); 10 | int arr[n]; 11 | int i,j; 12 | for(i = 0;i < n;i++) 13 | { 14 | scanf("%d ",&arr[i]); 15 | } 16 | int d,m; 17 | int sum = 0; 18 | int count = 0; 19 | scanf("%d %d",&d,&m); 20 | for(i = 0;i <= n-m;i++) 21 | { 22 | for(j = i;j < m+i;j++) 23 | { 24 | sum += arr[j]; 25 | } 26 | if(sum == d) 27 | { 28 | count++; 29 | } 30 | sum = 0; 31 | } 32 | printf("%d",count); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/BonAppetit.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int main() 13 | { 14 | int n,k; 15 | scanf("%d %d",&n,&k); 16 | int bill[n]; 17 | int i; 18 | for(i = 0;i < n;i++) 19 | { 20 | scanf("%d",&bill[i]); 21 | } 22 | int amt; 23 | scanf("%d",&amt); 24 | int sum = 0; 25 | for(i = 0;i < n;i++) 26 | { 27 | sum += bill[i]; 28 | } 29 | sum = sum - bill[k]; 30 | sum = sum/2; 31 | if(sum != amt) 32 | { 33 | printf("%d",abs(sum - amt)); 34 | } 35 | else 36 | { 37 | printf("Bon Appetit"); 38 | } 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/Camelcase.py: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # Complete the camelcase function below. 10 | def camelcase(s): 11 | count = 0 12 | l1 = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']; 13 | for i in s: 14 | if i in l1: 15 | count += 1 16 | return count + 1 17 | 18 | 19 | if __name__ == '__main__': 20 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 21 | 22 | s = raw_input() 23 | 24 | result = camelcase(s) 25 | 26 | fptr.write(str(result) + '\n') 27 | 28 | fptr.close() 29 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/Circular_Array_Rotation.py: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import sys 4 | 5 | n,k,q = input().strip().split(' ') 6 | n,k,q = [int(n),int(k),int(q)] 7 | a = list(map(int,input().strip().split(' '))) 8 | a = a[n-(k%n):]+a[:n-(k%n)] 9 | for a0 in range(q): 10 | m = int(input().strip()) 11 | print (a[m]) 12 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/Closest_Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | cin >> n; 8 | int arr[n]; 9 | for(int i = 0;i < n;i++) cin >> arr[i]; 10 | sort(arr,arr + n); 11 | int min = INT_MAX; 12 | for(int i = 1;i < n;i++) 13 | { 14 | if(arr[i] - arr[i-1] <= min) 15 | { 16 | min = arr[i] - arr[i-1]; 17 | } 18 | } 19 | 20 | for(int i = 1;i < n;i++) 21 | { 22 | if(arr[i] - arr[i-1] == min) 23 | { 24 | cout << arr[i-1] << " " << arr[i] << " "; 25 | } 26 | } 27 | cout << endl; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/Counting_Sort1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int n; 8 | cin >> n; 9 | int arr[n]; 10 | int count[101] = {}; 11 | for(int i = 0;i < n;i++) 12 | { 13 | cin >> arr[i]; 14 | count[arr[i]] += 1; 15 | } 16 | for(int i = 0;i < 100;i++) 17 | { 18 | cout << count[i] << " "; 19 | } 20 | cout << endl; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/Counting_Valleys.py: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # Complete the countingValleys function below. 10 | def countingValleys(n, s): 11 | j = 0 12 | count = 0 13 | for i in s: 14 | if i == 'U': 15 | j = j + 1 16 | if(j == 0): 17 | count += 1 18 | else: 19 | j = j - 1 20 | return count 21 | 22 | 23 | if __name__ == '__main__': 24 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 25 | 26 | n = int(raw_input()) 27 | 28 | s = raw_input() 29 | 30 | result = countingValleys(n, s) 31 | 32 | fptr.write(str(result) + '\n') 33 | 34 | fptr.close() 35 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/Divisible_Sum_Pairs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | int n,k; 14 | scanf("%d %d",&n,&k); 15 | int div[n]; 16 | int i; 17 | for(i = 0;i < n;i++) 18 | { 19 | scanf("%d",&div[i]); 20 | } 21 | int j; 22 | int sum = 0; 23 | int count = 0; 24 | for(i = 0;i < n;i++) 25 | { 26 | for(j = i + 1;j < n;j++) 27 | { 28 | sum = div[i] + div[j]; 29 | if(sum % k==0) 30 | { 31 | count++; 32 | } 33 | } 34 | } 35 | printf("%d",count); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/DrawingBook.py: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | from __future__ import print_function 4 | 5 | import os 6 | import sys 7 | 8 | # 9 | # Complete the pageCount function below. 10 | # 11 | def pageCount(n, p): 12 | # 13 | # Write your code here. 14 | # 15 | pages = min(p/2,n/2 - p/2) 16 | return pages 17 | 18 | if __name__ == '__main__': 19 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 20 | 21 | n = int(raw_input()) 22 | 23 | p = int(raw_input()) 24 | 25 | result = pageCount(n, p) 26 | 27 | fptr.write(str(result) + '\n') 28 | 29 | fptr.close() 30 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/Equalize_The_Array.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # Complete the equalizeArray function below. 10 | def equalizeArray(arr): 11 | dict = {} 12 | for i in arr : 13 | if i in dict : 14 | dict[i] += 1 15 | else : 16 | dict[i] = 1 17 | maximum_count = max(dict.values()) 18 | return (len(arr)-maximum_count) 19 | 20 | if __name__ == '__main__': 21 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 22 | 23 | n = int(input()) 24 | 25 | arr = list(map(int, input().rstrip().split())) 26 | 27 | result = equalizeArray(arr) 28 | 29 | fptr.write(str(result) + '\n') 30 | 31 | fptr.close() 32 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/Flipping_bits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // Complete the flippingBits function below. 6 | long flippingBits(long n) 7 | { 8 | return 4294967295 - n; 9 | 10 | } 11 | 12 | int main() 13 | { 14 | ofstream fout(getenv("OUTPUT_PATH")); 15 | 16 | int q; 17 | cin >> q; 18 | cin.ignore(numeric_limits::max(), '\n'); 19 | 20 | for (int q_itr = 0; q_itr < q; q_itr++) { 21 | long n; 22 | cin >> n; 23 | cin.ignore(numeric_limits::max(), '\n'); 24 | 25 | long result = flippingBits(n); 26 | 27 | fout << result << "\n"; 28 | } 29 | 30 | fout.close(); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/GameOfThrones1_Python: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | from collections import Counter 10 | 11 | # Complete the gameOfThrones function below. 12 | def gameOfThrones(s): 13 | d = dict(Counter(s)) 14 | odd_count = 0 15 | for letter_count in d.values(): 16 | if letter_count % 2 != 0: 17 | odd_count += 1 18 | if odd_count > 1: 19 | return 'NO' 20 | else: 21 | return 'YES' 22 | 23 | 24 | if __name__ == '__main__': 25 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 26 | 27 | s = raw_input() 28 | 29 | result = gameOfThrones(s) 30 | 31 | fptr.write(result + '\n') 32 | 33 | fptr.close() 34 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/Kangaroo_C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | int x1,v1,x2,v2; 14 | scanf("%d %d %d %d",&x1,&v1,&x2,&v2); 15 | double xrel = abs(x2 - x1); 16 | double vrel = abs(v2 - v1); 17 | double t = xrel/vrel; 18 | int t2 = xrel/vrel; 19 | if(x1 < x2 && v1 > v2 || x1 > x2 && v1 < v2) 20 | { 21 | if(t == t2) 22 | { 23 | printf("YES"); 24 | } 25 | else 26 | { 27 | printf("NO"); 28 | } 29 | } 30 | else 31 | { 32 | printf("NO"); 33 | } 34 | return 0; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/MIgratoryBirds_Python2: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # Complete the migratoryBirds function below. 10 | def migratoryBirds(arr): 11 | d = {} 12 | for i in arr: 13 | if i not in d: 14 | d[i] = 1 15 | else: 16 | d[i] += 1 17 | max = 0 18 | maxi = 5 19 | for i in d: 20 | if d[i] > max: 21 | maxi = i 22 | max = d[i] 23 | 24 | return maxi 25 | 26 | if __name__ == '__main__': 27 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 28 | 29 | arr_count = int(raw_input().strip()) 30 | 31 | arr = map(int, raw_input().rstrip().split()) 32 | 33 | result = migratoryBirds(arr) 34 | 35 | fptr.write(str(result) + '\n') 36 | 37 | fptr.close() 38 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/MarsExploration_C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | char message[10000]; 14 | int i; 15 | int count = 0; 16 | scanf("%s",message); 17 | int l = strlen(message); 18 | for(i = 0;i < l;i+=3) 19 | { 20 | if(message[i] != 'S') 21 | { 22 | count += 1; 23 | } 24 | if(message[i + 1] != 'O') 25 | { 26 | count += 1; 27 | } 28 | if(message[i + 2] != 'S') 29 | { 30 | count += 1; 31 | } 32 | } 33 | printf("%d",count); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/Pangrams_Python: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # Complete the pangrams function below. 10 | def pangrams(s): 11 | s = set(s.lower()) 12 | s.discard(" ") 13 | return "pangram" if len(s) == 26 else "not pangram" 14 | 15 | if __name__ == '__main__': 16 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 17 | 18 | s = raw_input() 19 | 20 | result = pangrams(s) 21 | 22 | fptr.write(result + '\n') 23 | 24 | fptr.close() 25 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/Service_Lane_C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | int n,t; 14 | scanf("%d %d",&n,&t); 15 | int i = 0; 16 | int arr[n]; 17 | for(i = 0;i < n;i++) 18 | { 19 | scanf("%d",&arr[i]); 20 | } 21 | while(t--) 22 | { 23 | int a,b; 24 | scanf("%d %d",&a,&b); 25 | int j = 0; 26 | int min = 100; 27 | for(j = a;j <= b;j++) 28 | { 29 | if(arr[j] < min) 30 | { 31 | min = arr[j]; 32 | } 33 | } 34 | printf("%d\n",min); 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/SockMerchant_Python: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # Complete the sockMerchant function below. 10 | def sockMerchant(n, ar): 11 | d = {} 12 | for i in ar: 13 | if i not in d: 14 | d[i] = 1 15 | else: 16 | d[i] += 1 17 | count = 0 18 | for i in d: 19 | count = count + d[i]/2 20 | return count 21 | 22 | if __name__ == '__main__': 23 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 24 | 25 | n = int(raw_input()) 26 | 27 | ar = map(int, raw_input().rstrip().split()) 28 | 29 | result = sockMerchant(n, ar) 30 | 31 | fptr.write(str(result) + '\n') 32 | 33 | fptr.close() 34 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/Solvemefirst_c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int solveMeFirst(int a, int b) { 7 | 8 | return a + b; 9 | } 10 | 11 | int main(void) 12 | { 13 | int n1, n2; 14 | scanf("%d %d", &n1, &n2); 15 | int sum; 16 | sum = solveMeFirst(n1, n2); 17 | printf("%d", sum); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/averybigsum_c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | int n; 14 | scanf("%d",&n); 15 | long long int arr[n]; 16 | int i; 17 | for(i = 0;i < n;i++) 18 | { 19 | scanf("%lld",&arr[i]); 20 | } 21 | long long int sum = 0; 22 | for(i = 0;i < n;i++) 23 | { 24 | sum += arr[i]; 25 | } 26 | printf("%lld",sum); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/debugging_XORstrings.py: -------------------------------------------------------------------------------- 1 | def strings_xor(s, t): 2 | res = "" 3 | for i in range(len(s)): 4 | if s[i] == t[i]: 5 | res += '0'; 6 | else: 7 | res += '1'; 8 | 9 | return res 10 | 11 | s = raw_input() 12 | t = raw_input() 13 | print strings_xor(s, t) 14 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/encryption.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // Complete the encryption function below. 6 | string encryption(string s) { 7 | 8 | 9 | } 10 | 11 | int main() 12 | { 13 | ofstream fout(getenv("OUTPUT_PATH")); 14 | 15 | string s; 16 | getline(cin, s); 17 | 18 | string result = encryption(s); 19 | 20 | fout << result << "\n"; 21 | 22 | fout.close(); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/first: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/sequenceEquation.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # Complete the permutationEquation function below. 10 | def permutationEquation(p): 11 | res = [] 12 | for i in range(len(p)): 13 | inter = p.index(i+1) 14 | y = p.index(inter+1) 15 | res.append(y+1) 16 | return res 17 | 18 | if __name__ == '__main__': 19 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 20 | 21 | n = int(input()) 22 | 23 | p = list(map(int, input().rstrip().split())) 24 | 25 | result = permutationEquation(p) 26 | 27 | fptr.write('\n'.join(map(str, result))) 28 | fptr.write('\n') 29 | 30 | fptr.close() 31 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/sherlock&squares_c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | int t; 14 | scanf("%d",&t); 15 | while(t > 0) 16 | { 17 | int a,b; 18 | scanf("%d %d",&a,&b); 19 | int supremum_a = ceil(sqrt(a)); 20 | int infemum_b = floor(sqrt(b)); 21 | int count = infemum_b - supremum_a + 1; 22 | printf("%d\n",count); 23 | t--; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/simplearraysum.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int summation(int a[] , int n){ 6 | if ( n == 0 ) 7 | return a[0]; 8 | else 9 | return a[n] + summation(a, n-1); 10 | } 11 | 12 | int main(void) 13 | { 14 | int n; 15 | scanf("%d",&n); 16 | 17 | int arr[n]; 18 | 19 | for(int i = 0;i < n;i++) 20 | scanf("%d",&arr[i]); 21 | 22 | int sum = summation(arr,n); 23 | 24 | printf("%d",sum); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /hackerrank/problem_solving/staircase.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | int n; 14 | scanf("%d",&n); 15 | int i,j,k; 16 | for(i=0;i 2 | 3 | using namespace std; 4 | 5 | // Complete the timeInWords function below. 6 | string timeInWords(int h, int m) { 7 | 8 | 9 | } 10 | 11 | int main() 12 | { 13 | ofstream fout(getenv("OUTPUT_PATH")); 14 | 15 | int h; 16 | cin >> h; 17 | cin.ignore(numeric_limits::max(), '\n'); 18 | 19 | int m; 20 | cin >> m; 21 | cin.ignore(numeric_limits::max(), '\n'); 22 | 23 | string result = timeInWords(h, m); 24 | 25 | fout << result << "\n"; 26 | 27 | fout.close(); 28 | 29 | return 0; 30 | } 31 | --------------------------------------------------------------------------------