├── .github ├── boring-cyborg.yml ├── stale.yml └── workflows │ └── pr-greeting.yml ├── .mergify.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── CSES_Problems ├── Bit Strings │ ├── problem.md │ └── solution.cpp ├── Distinct_Numbers │ ├── problem.md │ └── solution.cpp ├── Increasing_Array │ ├── problem.md │ └── solution.cpp ├── Maximum_Subarray_Sum │ ├── maxsubsum.cpp │ └── problem.md ├── Missing Number │ ├── problem.md │ └── solution.py ├── Range-Sum Query 1 │ ├── Problem.md │ └── Range-Sum Query.cpp ├── Repetitions │ ├── problem.md │ └── solution.py ├── Subarray Sum - I │ ├── problem.md │ └── solution.cpp ├── Subarray Sum - II │ ├── problem.md │ └── solution.cpp ├── Weird_Algorithm │ ├── Problem.md │ └── solution.c └── ferris_wheel │ ├── problem.md │ └── solution.cpp ├── CodeChef_problems ├── A Problem on Sticks │ ├── Solution.cpp │ ├── problem.md │ ├── solution.py │ └── solution2.py ├── AEIOUHW │ ├── problem.md │ └── solution.cpp ├── AND Plus OR │ ├── problem.md │ └── solution.cpp ├── ANIRWO │ ├── problem.md │ ├── solution.py │ └── solution2.cpp ├── ANUSQU │ ├── problem.md │ └── solution.py ├── ATTND │ ├── problem.md │ └── solution.cpp ├── AVGPR │ ├── problem.md │ └── solution.py ├── Ada King │ ├── problem.md │ └── solution.cpp ├── Ada Matrix │ └── problem.md ├── BINARR │ ├── problem.md │ └── solution.cpp ├── Bob and His Friends │ ├── Solution.py │ └── problem.md ├── CARSELL │ ├── problem.md │ └── solution.cpp ├── CENS20D │ ├── problem.md │ └── solution.cpp ├── CHEF AND CARD GAME │ ├── PROBLEM.MD.txt │ └── SOLUTION.cpp ├── CHEFEZQ │ ├── problem.md │ └── solution.cpp ├── CHEFINSQ │ ├── problem.md │ └── solution.py ├── CHEFK1 │ ├── problem.md │ └── solution.py ├── CHEFSTR1 │ ├── Solution.cpp │ ├── problem.md │ └── solution ├── CHEFWARS │ ├── problem.md │ └── solution.c ├── CHEFWED │ ├── Problem.md │ └── Solution.py ├── CHFICRM │ ├── Problem.md │ └── Solution.cpp ├── CHFINTRO │ ├── problem.md │ └── solution.cpp ├── CHFNSWPS │ ├── problem.md │ └── solution.py ├── CLLCM │ ├── problem.md │ └── solution.cpp ├── CLPNT │ ├── problem.md │ └── solution.cpp ├── COVIDLQ │ ├── problem.md │ └── solution.c ├── CRDGAME3 │ ├── problem.md │ └── solution.py ├── CSUM │ ├── problem.md │ └── solution.cpp ├── CVDRUN │ ├── problem.md │ └── solution.cpp ├── Chef Wars - Return of the Jedi │ ├── Solution.java │ └── problem.md ├── Chef and Card game │ ├── problem.md │ └── solution.py ├── Chef and Steps │ ├── problem.md │ └── solution.cpp ├── Chef and Street Food │ ├── problem.md │ └── solution.cpp ├── Chef and String │ ├── problem.md │ └── solution.cpp ├── ELEVTR │ ├── problem.md │ └── solution.cpp ├── EVENM │ ├── Problem.md │ └── Solution.cpp ├── Enormous Input Test │ ├── problem.md │ └── solution.cpp ├── FIBEASY │ ├── problem.md │ └── solution.py ├── FINXOR │ ├── problem.md │ └── solution.cpp ├── Factorial │ ├── problem.md │ └── solution.cpp ├── GCD operations │ ├── problem.md │ └── solution.cpp ├── ICPC_Selection │ ├── problem.md │ └── solution.cpp ├── KJCP02 │ ├── problem.md │ └── solution.cpp ├── LAPD │ ├── problem.md │ └── solution.py ├── LINCHESS │ ├── problem.md │ └── solution.py ├── Laddu Accural System │ ├── problem.md │ └── solution.py ├── Lapindromes │ ├── problem.md │ └── solution.cpp ├── MINDSUM │ ├── problem.md │ └── solution.cpp ├── MISSP │ ├── problem.md │ └── solution.cpp ├── Minimum Insertions │ ├── problem.md │ └── solution.cpp ├── Multiple of 3 │ ├── problem.md │ └── solution.cpp ├── POSAND │ ├── problem.md │ └── solution.cpp ├── POTATOES │ ├── Problem.md │ └── Solution.cpp ├── PPATTERN │ ├── PPATTERN.py │ └── Problem.md ├── PRICECON │ ├── Problem.md │ └── Solution.cpp ├── PTMSSNG │ ├── problem.md │ └── solution.cpp ├── REPLESX │ ├── Problem.md │ └── Solution.py ├── RPD │ ├── problem.md │ └── solution.cpp ├── SCAT2020 │ ├── SC_02.py │ └── problem.md ├── Strike or Spare │ ├── Problem.md │ └── Solution.cpp ├── The Tom and Jerry Game! │ ├── problem.md │ ├── solution.cpp │ └── solution2.cpp ├── UNITGCD │ ├── problem.md │ └── solution.cpp ├── WATERMELON │ ├── PROBLEM.MD.txt │ └── SOLUTION.cpp ├── WATMELON │ ├── problem.md │ └── solution.cpp ├── XORAGN │ ├── problem.md │ └── solution.py ├── XYSTR │ ├── Problem.md │ ├── Solution.cpp │ └── Solution.py └── uncle_jhony │ ├── problem.md │ └── solution.py ├── CodeSignal_problems └── AdjacentElementsProduct │ ├── Problem.md │ ├── solution.js │ └── solution1.py ├── Codeforces_problems ├── A and B and Team Training │ ├── problem.md │ └── solution.cpp ├── A. Team │ ├── problem.md │ └── solution.cpp ├── ABBB │ ├── problem.md │ └── soultion.cpp ├── Balanced ArrayB │ ├── problem.md │ └── solution.cpp ├── Bargain │ ├── problem.md │ └── solution.cpp ├── Barrels │ ├── problem.md │ └── soultion.cpp ├── Beautiful Matrix │ ├── problem.md │ └── solution.cpp ├── Boy or Girl 236A │ ├── problem.md │ └── solution.cpp ├── CandiesA │ ├── problem.md │ └── solution.py ├── Chef Monokarp │ ├── problem.md │ └── solution.cpp ├── Common SubsequenceA │ ├── problem.md │ └── solution.py ├── CowAndHaybales1307A │ ├── CowAndHaybales1307A.md │ └── codeforces1307A.cpp ├── CrazyComputer716A │ ├── CrazyComputer716A.md │ └── codeforces716A.cpp ├── Cubes Sorting1420A │ ├── Solution.cpp │ └── problem.md ├── Dice Tower │ ├── problem.md │ └── solution.cpp ├── Divide It A │ ├── problem.md │ └── solution.py ├── Dominant Piranha │ ├── problem.md │ └── solution.cpp ├── Domino Piling │ ├── problem.md │ └── solution.py ├── Drazil and Factorial │ ├── problem.md │ └── solution.cpp ├── Dreamoon and WIFI │ ├── problem.md │ └── solution.cpp ├── Equalize │ ├── problem.md │ └── solution.cpp ├── Even Odds │ ├── Problem.md │ └── Solution.cpp ├── Fence │ ├── problem.md │ └── solutions.cpp ├── Fibonacci army 72G │ ├── problem.md │ └── solution.cpp ├── FloorNumber │ ├── problem.md │ └── solution.cpp ├── GCD Compression B │ ├── problem.md │ └── solution.py ├── Good_Number │ ├── problem.md │ └── solution.cpp ├── Greg's Workout │ ├── problem.md │ └── solution.cpp ├── Kevin and Grid │ ├── problem.md │ └── solution.cpp ├── Lineland Mail │ ├── problem.md │ └── solution.cpp ├── Love A │ ├── problem.md │ └── solution.cpp ├── Luxurious Houses │ ├── problem.md │ └── solutions.cpp ├── Maximum GCD A │ ├── problem.md │ └── solution.py ├── Merge It A │ ├── problem.md │ └── solution.py ├── Mike And Cellphones 689A │ ├── problem.md │ └── solution.cpp ├── Minimum Ternary String │ ├── problem.md │ └── soultion.cpp ├── New Theatre Square │ ├── problem.md │ └── solution.cpp ├── Next Round │ ├── problem.md │ ├── solution.cpp │ └── solution.py ├── Nice Matrix │ ├── problem.md │ └── solution.cpp ├── Number Game │ ├── problem.md │ └── solution.py ├── Numbers on Whiteboard │ ├── problem.md │ └── solution.cpp ├── Remove Smallest │ ├── Problem.md │ └── Solution.cpp ├── Restore the Permutation by Merger │ ├── Problem.md │ └── Solution.cpp ├── Reverse Binary Strings │ ├── problem.md │ └── solution.py ├── RockPaperScissors │ ├── problem.md │ └── solution.cpp ├── Semifinals │ ├── problem.md │ └── soultion.cpp ├── Songs Compression │ ├── problem.md │ └── solution.cpp ├── Subset Mex │ ├── problem.md │ └── solutions.cpp ├── Tavas and Nafas │ ├── Problem.md │ └── Solution.cpp ├── Tavas and SaDDas │ ├── problem.md │ └── solution.cpp ├── Team │ ├── problem.md │ ├── solution.cpp │ └── solution.py ├── Telephone Number 1167A │ ├── problem.md │ └── solution.cpp ├── Ternary Sequence1401B │ ├── problem.md │ └── solution.cpp ├── Theatre Square │ ├── problem.md │ └── solution.py ├── Towers │ ├── problem.md │ └── soultion.cpp ├── TurnTheRectangles │ ├── problem.md │ └── solution.cpp ├── Two Platforms │ ├── problem.md │ └── solution.cpp ├── Vanya and Lanterns │ ├── problem.md │ └── solution.cpp ├── Vasya and String │ ├── problem.md │ └── solution.cpp ├── Way too long words │ ├── problem.md │ └── solution.py ├── XXXXX │ ├── problem.md │ └── solution.cpp ├── Yet Another Bookshelf 1433B │ ├── problem.md │ ├── solution.cpp │ └── solution.py ├── Young Physicist │ ├── problem.md │ └── solution.py ├── Zero Remainder Sum │ ├── problem.md │ └── solution.cpp ├── buttons │ ├── problem.md │ └── solution.cpp ├── decoding │ ├── problem.md │ └── solution.cpp ├── police recruits │ ├── problem.md │ └── solution.cpp ├── sum of digits │ ├── problem.md │ └── solution.cpp └── watermelon │ ├── problem.md │ └── solution.cpp ├── Codewars_problems ├── Disemvowel Trolls │ ├── problem.md │ └── solution.c ├── Duplicate sandwich │ ├── problem.md │ └── solution.js ├── Highest and Lowest │ ├── problem.md │ └── solution.js ├── Least Larger │ ├── problem.md │ └── solution.js ├── Probabilities for Sums in Rolling Cubic Dice │ ├── problem.md │ └── solution.py ├── Traffic light │ ├── problem.md │ └── solution.js └── Where my Anagrams At │ ├── problem.md │ └── solution.js ├── Exercism_Problems └── space_age │ ├── problem.md │ └── solution.js ├── GeeksForGeeks ├── Arya_Long_String │ ├── Problem.md │ └── Solution.cpp ├── Blum Integer │ ├── problem.md │ └── solution.py ├── Count_of_Vessels │ ├── Problem.md │ ├── Solutions.md │ └── assets │ │ ├── out.png │ │ └── out2.png ├── Detect Loop in Linked List │ ├── Solution.java │ ├── problem.md │ └── solution.cpp ├── Kadane's Algorithm │ ├── Problem.md │ ├── solution.cpp │ └── solution.py ├── Kth_Smallest_Element │ ├── Problem.md │ ├── Solution.cpp │ └── Solution3.cpp ├── Largest Histogram │ ├── problem.md │ └── solution.cpp ├── Longest Palindrome in String │ ├── problem.md │ └── solution.cpp ├── Merge_Sort_for_Linked_List │ ├── Problem.md │ └── Solution.cpp ├── Number of islands │ ├── Islands.java │ └── problem.md ├── Palindrome_Linked_List │ ├── Problem.md │ └── Solution.cpp ├── Pallindrome String │ ├── problem.md │ ├── solution.java │ ├── solution2.py │ └── solution3.py ├── Parenthesis_Checker │ ├── Problem.md │ └── Solution.cpp ├── QueueUsingStacks │ ├── problem.md │ └── solution.cpp ├── Remove duplicate elements from sorted Array │ ├── Problem.md │ └── Solution.cpp ├── Rotate_by_90_degrees │ ├── Problem.md │ └── Solution.cpp ├── Sister_and_Coins │ ├── Problem.md │ └── Solution.cpp ├── StackUsingQueus │ ├── problem.md │ └── solution.cpp └── SumOfPairs │ ├── problem.md │ ├── solution1.py │ └── solution2.py ├── HackerEarth_problems ├── 13 Reasons Why │ ├── problem.md │ └── solution1.py ├── Balancing cubes │ ├── problem.md │ └── solution.cpp ├── Best Index │ ├── problem.md │ └── solution.cpp ├── Big P and Party │ ├── problem.md │ └── solution.cpp ├── Dhoom 4 │ ├── problem.md │ └── solution.cpp ├── Edges on a path │ ├── problem.md │ └── solution.py ├── Hey! Please help Pradyumn! │ ├── Problem.md │ └── Solution.cpp ├── Micro and Array Update │ ├── problem.md │ └── solution.py ├── New Friends │ ├── problem.md │ └── solution.cpp ├── Odd one out │ ├── problem.md │ └── solution.cpp ├── Paths in the Graph │ ├── Problem.md │ └── Solution.py ├── Pizza Confusion │ ├── problem.md │ └── solution.cpp ├── Prasanjeet verma and his sorrow │ ├── Problem.md │ └── Solution.cpp ├── RepeatedKTimes │ ├── problem.md │ └── solution.cpp ├── Rotation │ ├── problem.md │ └── solution.cpp ├── Seating Arrangement │ ├── Problem.md │ └── seating_arrangement.py ├── Shubham and Subarray Xor │ ├── problem.md │ └── solution.cpp ├── Subarrays XOR │ ├── Problem.md │ └── Solution.cpp ├── Xenny and Partially Sorted Strings │ ├── problem.md │ └── solution.py ├── benny and broken odometer │ ├── Problem.md │ └── Solution.cpp └── e-maze-in │ ├── problem.md │ └── solution.java ├── Hackerrank_problems ├── 2D Arrays │ ├── problem.md │ ├── solution.cpp │ └── solution.java ├── 3D_Surface_Area │ ├── Problem.md │ ├── solution.cpp │ └── solution2.cpp ├── A Personalized Echo │ ├── problem.md │ └── solution.sh ├── Angry Professor │ ├── problem.md │ ├── solution.cpp │ └── solution.py ├── Apple and Orange │ ├── problem.md │ └── solution1.py ├── Arithmetic Operators │ ├── problem.md │ └── solution.py ├── Array Manipulation │ ├── Solution1.py │ ├── problem.md │ ├── solution.cpp │ └── solution.py ├── BeautifulDaysAtTheMovies │ ├── problem.md │ ├── solution.cpp │ └── solution.py ├── Big_Sorting │ ├── problem.md │ └── solution.py ├── Bigger is Greater │ ├── BiggerIsGreater.java │ ├── README.md │ └── solution2.cpp ├── Binary numbers │ ├── problem.md │ └── solution.C ├── Birthday_chocolate │ ├── problem.md │ └── solution.py ├── Bitwise_operator │ ├── PROBLEM.md │ └── SOLUTION.c ├── Boxes_Through_a_Tunnel │ ├── Problem.md │ └── Solution.c ├── Breaking Records │ ├── Problem.md │ └── solution.java ├── Cats and a Mouse │ ├── problem.md │ └── solution.py ├── Check_LeapYear │ ├── problem.md │ └── solution.py ├── Chocolate Feast │ ├── problem.md │ └── solution.cpp ├── Circular Array Rotation │ ├── problem.md │ └── solution.py ├── Common Child │ ├── problem.md │ └── solution.cpp ├── Compare The Triplets │ ├── compare_the_triplets.py │ └── problem.md ├── Comparing Numbers │ ├── problem.md │ └── solution.sh ├── CreditCardValid │ ├── problem.md │ └── solution.py ├── Currency-formatter │ ├── problem.md │ └── solution.java ├── Cut The Sticks │ ├── problem.md │ └── soloution.py ├── Cycle Detection │ ├── problem.md │ └── solution.py ├── Day 29 Bitwise AND Problem │ ├── problem.md │ └── solution.py ├── Day_Of_The_Programmer │ ├── solution.rb │ ├── solution2.cpp │ └── solution2.py ├── Designer PDF Viewer │ ├── problem.md │ └── solution.c ├── Divisible Sum Pairs │ ├── problem.md │ └── solution.cpp ├── Diwali Lights │ ├── problem.md │ └── solution 1.cpp ├── DrawingBook │ ├── Solution.py │ ├── Solution2.java │ ├── Solution2.py │ ├── problem.md │ └── solution.js ├── ElectronicShop │ ├── Problem.md │ ├── solution.py │ ├── solution2.py │ └── solution3.cpp ├── EquilibriumPoint in array │ ├── problem.md │ └── solution.cpp ├── Extra Long Factorials │ ├── problem.md │ └── solution.C ├── Fibonacci-Series │ ├── Solution.py │ └── problem.md ├── Find Merge Point of Two Lists │ ├── problem.md │ └── solution.py ├── Find_a_String │ ├── Problem.md │ └── Solution.py ├── Find_a_point │ ├── problem.md │ └── solution.py ├── Find_digits │ ├── problem.md │ └── solution.cpp ├── FizzBuzz │ ├── Problem.md │ ├── Solution2.py │ └── solution.py ├── Game of Thrones - I │ ├── problem.md │ └── solution.c ├── Getting started with conditionals │ ├── problem.md │ └── solution.sh ├── Hackfest2020 │ ├── GameOfMaximization │ │ ├── gameOfMaximization.cpp │ │ └── problem.md │ └── StrictlyIncreasingSequence │ │ ├── problem.md │ │ └── strictlyIncreasingSequence.cpp ├── Halloween Party │ ├── problem.md │ └── solution.py ├── Hotel Price │ ├── problem.md │ └── solution.cpp ├── If-Else │ ├── problem.md │ └── solution.java ├── Intro to Conditional Statements │ ├── problem.md │ └── solution.cpp ├── Is This a Binary Search Tree │ ├── problem.md │ └── solution.py ├── Journey to the moon │ ├── problem.md │ └── solution.cpp ├── Jumping on the Clouds │ ├── problem.md │ └── solution.py ├── Keyword_Transposition_Cipher │ ├── problem.md │ └── solution.py ├── Let's Review │ ├── problem.md │ └── solution.C ├── Library Fine │ ├── problem.md │ └── solution.py ├── Making Anagrams │ ├── Problem.md │ └── solution.cpp ├── Mars Exploration │ ├── problem.md │ └── solution.cpp ├── Max_Min │ ├── problem.md │ └── solution.cpp ├── Maximize_It! │ ├── problem.md │ └── solution.py ├── Maximum_draws │ ├── problem.md │ └── solution.py ├── Migratory Birds │ ├── problem.md │ └── solution.py ├── Mini-Max Sum │ ├── problem.md │ └── solution.py ├── MinimumHeightOFTriangle │ ├── problem.md │ └── solution.py ├── Modified Kaprekar Numbers │ ├── problem.md │ └── solution.py ├── Nested Lists │ ├── problem.md │ └── solution.py ├── Non_divisible_Subset │ ├── problem.md │ └── solution.cpp ├── Operators │ ├── Problem.md │ └── Solution.cpp ├── Organizing_container_of_balls │ ├── Problem.md │ └── solution.py ├── Pairs │ ├── problem.md │ └── solution.cpp ├── Picking Numbers │ ├── problem.md │ └── solution.py ├── Queue using Two Stacks │ ├── problem.md │ └── solution.py ├── Recursion_Fibonacci_Numbers │ ├── problem.md │ └── solution.py ├── Repeated String │ ├── Problem.md │ └── Solution.py ├── Restaurant │ ├── problem.md │ └── solution.c++ ├── Reverse Game │ ├── problem.md │ └── solution.py ├── Reverse Linked List │ ├── problem.md │ └── solution.py ├── Road and Libraries │ ├── problem.md │ └── solution.cpp ├── Sales by Match │ ├── Problem.md │ └── solution.py ├── Sam and substrings │ ├── problem.md │ └── solution.cpp ├── Sequence Equation │ ├── Problem.md │ ├── Solution.java │ ├── Solution_4.py │ ├── solution.cpp │ ├── solution2.cpp │ └── solution3.py ├── Service Lane │ ├── problem.md │ └── solution.c ├── Sherlock and valid strings │ ├── problem.md │ ├── solution.py │ └── solution2.py ├── Sherlock_and_Permutation │ ├── problem.md │ └── solution.py ├── Simple Text Editor │ ├── problem.md │ └── solution.py ├── Solve_me_first │ ├── Problem.md │ ├── Solution2.py │ ├── solution.java │ ├── solution1_MultipleWays.py │ └── solve_me_first_solution2 ├── Sparse Array │ ├── Problem.md │ └── Solution.py ├── Summing_n_series │ ├── problem.md │ └── solution.py ├── Time_Conversion │ ├── problem.md │ └── time_conversion.py ├── Time_In_Words │ ├── Problem.md │ └── solution.cpp ├── Tower_of_Hanoi_Recursion │ ├── problem.md │ ├── solution.cpp │ └── solution.py ├── Triangle_Quest │ ├── problem.md │ └── solution.py ├── Triangle_Quest_2 │ ├── Problem.md │ └── Solution.py ├── Variablesize_array │ ├── Solution.cpp │ └── problem.md ├── array-reversal │ ├── problem.md │ └── solution.c ├── array_left_rotation │ ├── Problem.md │ └── array_left_rotation.py ├── counting_valleys │ ├── Solution.java │ ├── problem.md │ ├── solution.py │ └── solution1_CountingValleys.py ├── day_of_the_programmer │ ├── problem.md │ └── solution.py ├── diagonal-difference │ ├── problem.md │ ├── solution.cpp │ ├── solution.java │ └── solution.py ├── kangaroo │ ├── Problem.md │ ├── kangaroo_solution3.py │ ├── solution.py │ ├── solution1.py │ ├── solution2.cpp │ ├── solution3.py │ ├── solution4.py │ └── solution5.cpp ├── loops │ ├── Solution1.py │ ├── problem.md │ └── solution.py └── staircase │ ├── problem.md │ └── solution.cpp ├── InterviewBit_problems ├── BinaryTree_PreorderTraversal │ ├── Problem.md │ └── Solution.cpp ├── CP_BinaryTree │ ├── Problem.md │ └── Solution.cpp ├── EncodingBased problem │ ├── Problem.md │ └── Solution.cpp ├── LeastCommonAncestor │ ├── problem.md │ └── solution.cpp ├── Math_Section │ ├── Problem.md │ ├── Problem_2.md │ ├── Solution.cpp │ └── Solution_2.cpp ├── Sorting │ ├── Hotel Booking │ │ ├── problem.md │ │ └── solution.py │ ├── Max NonNegative SubArray │ │ ├── problem.md │ │ └── solution.py │ ├── Max Sum Contiguous SubArray │ │ ├── problem.md │ │ └── solution.py │ └── Max Unsorted SubArray │ │ ├── problem.md │ │ └── solution.py ├── Stack and Queues │ └── Largest Rectangle in Histogram │ │ ├── problem.md │ │ └── solution.cpp ├── Symmetric_Traversal │ ├── Problem.md │ └── Solution.cpp └── TwoPointers │ ├── Merger2SortedList │ ├── problem.md │ └── solution.cpp │ ├── remove_duplicate_elements │ ├── problem.md │ └── solution.cpp │ ├── remove_duplicate_elements_II │ ├── problem.md │ └── solution.cpp │ └── remove_givenElement_from_array │ ├── problem.md │ └── solution.cpp ├── LICENSE ├── LeetCode_problems ├── Add Strings │ ├── Solution.py │ ├── problem.md │ └── solution.cpp ├── Add Two Numbers Linked List │ ├── problem.md │ └── solution.py ├── Anagrams │ ├── Solution.java │ └── problem.md ├── Array Partition 1 │ ├── problem.md │ └── solution(1).py ├── Binary_Tree_level_Order_Traversal │ ├── problem.md │ └── sol.java ├── Combination Sum │ ├── Solution.py │ └── problem.md ├── Compare Version Number │ ├── problem.md │ ├── solution.cpp │ └── solution2.cpp ├── Container With Most Water │ ├── Solution.java │ ├── Solution.py │ └── problem.md ├── Convert Roman number to Integer │ ├── problem.md │ └── solution.java ├── Count All Valid Pickup and Delivery Options │ ├── problem.md │ └── solution.cpp ├── Count Square Submatrices with All Ones │ ├── problem.md │ └── solution.java ├── Count and Say │ ├── question.md │ └── solution.cpp ├── Cycle Detection in Linked List │ ├── Solution.py │ └── problem.md ├── DecryptStringFromAlphabetToInteger │ ├── problem.md │ └── solution.cpp ├── Defanging an IP Address │ ├── problem.md │ └── solution.py ├── Delete Node │ ├── Problem.md │ └── Solution.java ├── Distinct Subsequence II │ ├── problem.md │ └── solution.cpp ├── Dungeon Game │ ├── problem.md │ └── solution.cpp ├── Find all duplicates in an array │ ├── Solution.java │ └── problem.md ├── Find_the_Difference │ ├── problem.md │ └── solution.py ├── First Missing Positive │ ├── Solution.cpp │ ├── problem.md │ └── solution.py ├── First_Unique_Character_in_a_String │ ├── problem.md │ └── solution.py ├── Gas Station │ ├── problem.md │ └── solution.cpp ├── H_Index │ ├── problem.md │ └── solution.py ├── Insert Interval │ ├── InsertInterval.java │ ├── problem.md │ └── solution.cpp ├── Invert Binary Tree │ ├── invert_binary_Tree.py │ └── problem.md ├── Jewels and Stones │ ├── problem.md │ ├── solution.cpp │ └── solution.py ├── K Closest Points to Origin │ ├── Problem.md │ └── Solution.java ├── Least Number of Unique Integers after K Removals │ ├── problem.md │ └── solution.py ├── Length of Last Word │ ├── problem.md │ └── solution.cpp ├── Linked List Components │ ├── problem.md │ └── solution.cpp ├── Longest Substring Without Repeating Characters │ ├── Problem.md │ └── Solution.cpp ├── Majority Element │ ├── problem.md │ ├── solution1.py │ └── solution2.cpp ├── Max Area of Island │ ├── problem.md │ └── solution.cpp ├── Max level Sum Of Binary Tree │ ├── Max_Level.md │ └── Solution.java ├── Maximum Product Subarray │ ├── problem.md │ └── solution.py ├── Maximum Sum Circular Subarray │ ├── problem.md │ └── solution.cpp ├── Median_of_two_sorted_array │ ├── problem.md │ └── solution.cpp ├── Minimum Path Sum │ ├── Solution.java │ └── problem.md ├── Minimum Size Subarray │ ├── problem.md │ └── solution1.cpp ├── Monotonic Array │ ├── problem.md │ └── solution_1.py ├── Next Permutation │ ├── problem.md │ └── solution.cpp ├── Number of Islands │ ├── problem.md │ └── solution1.cpp ├── Number_of_good_pairs │ ├── problem.md │ └── solution.cpp ├── Permutation Palindrome │ ├── Problem Statement.md │ └── Solution.md ├── Permutation Sequence │ ├── Problem.md │ └── Solution.cpp ├── Plus One │ ├── plusOne.java │ └── problem.md ├── Possible Bipartition │ ├── Problem.md │ └── Solution.java ├── Predict the winner │ ├── Problem.md │ └── Solution.py ├── Queue Reconstruction by Height │ ├── Question.txt │ └── Solution.cpp ├── Range addition II │ ├── problem.md │ └── solution.cpp ├── Remove Covered Intervals │ ├── Solution.java │ └── problem.md ├── Remove Duplicates from Sorted List │ ├── Problem.md │ └── Solution ├── Remove Element │ ├── problem.md │ └── solution.cpp ├── Remove Nth Node from End │ ├── problem.md │ └── solution.cpp ├── Reorder_List │ ├── problem.md │ └── solution.cpp ├── Reverse Integer │ ├── problem.md │ └── solution.cpp ├── Roman to Integer │ ├── problem.md │ └── solution.cpp ├── Rotate Digits │ ├── problem.md │ └── solution.js ├── Rotate Image │ ├── problem.md │ └── solution.js ├── Running Sum of 1d Array │ ├── problem.md │ └── solution.py ├── Same Tree │ ├── problem.md │ └── sameTree.java ├── Search Rotated Sorted Array │ ├── Solution.java │ └── problem.md ├── Single Number │ ├── problem.md │ └── solution.cpp ├── Spiral Matrix II │ ├── problem.md │ └── solution.java ├── Spiral Matrix │ ├── problem.md │ └── solution.py ├── String to Integer (ATOI) │ ├── Solution.py │ └── problem.md ├── Subarray Sums Divisible by K │ ├── problem.md │ └── solution.cpp ├── Trapping-rain-water │ ├── Solution.java │ └── problem.md ├── Unique Paths II │ ├── problem.md │ └── solution1.cpp ├── Unique Paths III │ ├── problem.md │ └── solution.cpp ├── UniqueMorseCode │ ├── problem.md │ └── solution.cpp ├── Wildcard_Matching │ ├── problem.md │ └── solution.py ├── Winner of an Array Game │ ├── Solution.py │ ├── readme.md │ └── solution.cpp ├── Wriggle_Sort_2 │ ├── problem.md │ └── solution.cpp ├── XOR Operation in an Array │ ├── problem.md │ └── solution.py ├── add digits │ ├── problem.md │ └── solution.cpp ├── add one row to tree │ ├── problem.md │ └── solution.cpp ├── add-binary │ ├── Solution.py │ └── problem.md ├── all elements in two binary search trees │ ├── problem.md │ └── solution.cpp ├── count-good-triplets │ ├── Solution.py │ └── problem.md ├── first-bad-version │ ├── Solution.py │ └── problem.md ├── graph clone │ ├── problem.md │ └── solution.cpp ├── insert-into-a-binary-search-tree │ └── Add Strings │ │ ├── Solution.py │ │ └── problem.md ├── kth-smallest-element-in-a-bst │ ├── Solution.py │ └── problem.md ├── kth_factor_of_n │ ├── Problem.md │ └── solution.py ├── merge k sorted list │ ├── Solution.java │ └── problem.md ├── merge two linked list │ └── problem.md ├── merge two sorted linked list │ └── Solution.py ├── range-sum-of-bst │ ├── Solution.py │ └── problem.md └── subsets │ ├── problem.md │ └── solution.cpp ├── Misc ├── Caesar_Cipher_Encryptor │ ├── problem.md │ ├── solution.py │ └── solution2.py ├── Deja_vu │ ├── Instructions.jpg │ ├── readme.md │ └── solution1.py ├── Dynamic_Programming_Knapsack_Problem │ ├── Problem.md │ └── Solution.py ├── Fibonacci_Search │ ├── Problem.md │ └── solution.java ├── H Pattern Problem │ ├── Problem.md │ └── Solution.py ├── Heap_Sort │ ├── problem.md │ └── solution.java ├── HiveMaker │ ├── HikeMaver.md │ ├── solution_1.py │ └── solution_2.py ├── Math and Strings Problems │ ├── Anagram Problem │ │ ├── problem statement.txt │ │ └── solution.java │ ├── Armstrong Number Problem │ │ ├── Problem Statement.txt │ │ └── Solution.java │ ├── Spy Number Problem │ │ ├── problem statement.txt │ │ └── solution.java │ └── The One with the Fibonacci │ │ ├── problem statement.txt │ │ └── solution.java ├── Monotonic_Array │ ├── problem.md │ ├── solution.py │ └── solution2.py ├── SparseMatrix_Multiplication │ └── problem.md └── SumOfAllDigits │ ├── problem.md │ ├── solution1.py │ └── solution2.cpp ├── PULL_REQUEST_TEMPLATE.md ├── README.md ├── Spoj_problems ├── ACPC10A │ ├── problem.md │ └── solution.cpp ├── ADDREV │ ├── problem.md │ └── solution.cpp ├── CANDY │ ├── problem.md │ └── solution.cpp ├── FCTRL │ ├── problem.md │ └── solution.cpp ├── FCTRL2 │ ├── problem.md │ └── solution.cpp ├── NSTEPS │ ├── problem.md │ └── solution.cpp ├── ONP │ ├── problem.md │ └── solution.cpp ├── PRIME1 │ ├── problem.md │ └── solution.cpp ├── SAMER08F │ ├── problem.md │ └── solution.cpp └── TEST │ ├── problem.md │ └── solution.cpp ├── USEFUL_RESOURCES.md └── project_euler_problems ├── 10001st prime ├── problem.md ├── solution.c ├── solution.js └── solution.py ├── CountingSundays ├── problem.md └── solution.cpp ├── EvenFibonacciNumbers ├── problem.md └── solution.cpp ├── Largest Product in a Grid ├── Problem.md └── solution.cpp ├── SumSquareDifference ├── problem.md └── solution.cpp ├── digit factorials ├── problem.md └── solution.cpp ├── integer right triangle ├── problem.md ├── solution.cpp └── solution.py ├── lattice paths ├── problem.md └── solution.js └── summation of primes ├── problem.md ├── solution.c ├── solution.js └── solution.py /.github/boring-cyborg.yml: -------------------------------------------------------------------------------- 1 | ##### Greetings ######################################################################################################## 2 | # Comment to be posted to welcome users when they open their first PR 3 | firstPRWelcomeComment: > 4 | Hi there :wave: Congratulations on sending your first PR here :sparkles: Your PR will be reviewed soon, in the meantime it would be great if you could star :star: this repo :smiley: 5 | 6 | -------------------------------------------------------------------------------- /.github/workflows/pr-greeting.yml: -------------------------------------------------------------------------------- 1 | name: "PR Greeter" 2 | on: [pull_request] 3 | 4 | jobs: 5 | pr-greeter: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - name: "Greeter" 9 | uses: JJ/pr-greeting-action@releases/v0 10 | with: 11 | repo-token: ${{ secrets.GITHUB_TOKEN }} 12 | pr-message: "Hi there :wave: Congratulations on sending your first PR here :sparkles: \nYour PR will be reviewed soon, in the meantime it would be great if you could star :star: this repo :smiley:" 13 | -------------------------------------------------------------------------------- /.mergify.yml: -------------------------------------------------------------------------------- 1 | pull_request_rules: 2 | - name: Automatic comment on approval 3 | conditions: 4 | - "#approved-reviews-by>=1" 5 | actions: 6 | comment: 7 | message: Awesome :thumbsup:, Thanks for contributing :smiley:! 8 | -------------------------------------------------------------------------------- /CSES_Problems/Bit Strings/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://cses.fi/problemset/task/1617/ 2 | -------------------------------------------------------------------------------- /CSES_Problems/Bit Strings/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | 5 | /* 6 | The question is simple, we need to find the number of all possible binary string of length n, 7 | So for each position we have two options, either it is 1 or it is 0, so the answer will be ((2 ^ n) % mod). 8 | */ 9 | 10 | signed main() { 11 | int n; 12 | cin >> n; 13 | const int mod = 1e9 + 7; 14 | int ans = 1; 15 | for(int i = 0; i < n; i++) { 16 | ans *= 2; 17 | ans %= mod; 18 | } 19 | cout << ans <<"\n"; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /CSES_Problems/Distinct_Numbers/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://cses.fi/problemset/task/1621/ 2 | -------------------------------------------------------------------------------- /CSES_Problems/Distinct_Numbers/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | 5 | /* 6 | Idea is simple, if we want to find the distinct numbers in the array, 7 | We can insert all the elements in the set and simply return the size of the set. 8 | */ 9 | 10 | signed main() { 11 | int n; 12 | cin >> n; 13 | set s; 14 | for(int i = 0; i < n; i++) { 15 | int x; 16 | cin >> x; 17 | s.insert(x); 18 | } 19 | cout << (int)s.size() <<"\n"; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /CSES_Problems/Increasing_Array/problem.md: -------------------------------------------------------------------------------- 1 | Link to the problem statement : https://cses.fi/problemset/task/1094 2 | --------------------------------------------------------------------------------------------- 3 | Please visit the link for the problem statement and then try it youself, and then go for the solution. 4 | -------------------------------------------------------------------------------- /CSES_Problems/Maximum_Subarray_Sum/problem.md: -------------------------------------------------------------------------------- 1 | Link to the problem statement : https://cses.fi/problemset/task/1643 2 | --------------------------------------------------------------------------------------------- 3 | Please visit the link for the problem statement and then try it youself, and then go for the solution. 4 | -------------------------------------------------------------------------------- /CSES_Problems/Missing Number/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://cses.fi/problemset/task/1083 -------------------------------------------------------------------------------- /CSES_Problems/Missing Number/solution.py: -------------------------------------------------------------------------------- 1 | def missing_num(n): 2 | n=sorted(n) # shuffling the items of n in a sorted manner 3 | n.append(0) #adding the number 0 at the end for checking purpose 4 | for i in range(1,len(n)+1): 5 | if i!=n[i-1]: # checking for the missing number 6 | return i # returning the missing number 7 | 8 | input() 9 | n = list(map(int, input().split(" "))) # Splitting the input line in a list 10 | print(missing_num(n)) # Calling the missing_num(n) function and printing the returned value -------------------------------------------------------------------------------- /CSES_Problems/Range-Sum Query 1/Problem.md: -------------------------------------------------------------------------------- 1 | Link :- https://cses.fi/problemset/task/1646 -------------------------------------------------------------------------------- /CSES_Problems/Repetitions/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://cses.fi/problemset/task/1069/ -------------------------------------------------------------------------------- /CSES_Problems/Subarray Sum - I/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://cses.fi/problemset/task/1660/ 2 | -------------------------------------------------------------------------------- /CSES_Problems/Subarray Sum - II/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://cses.fi/problemset/task/1661 2 | -------------------------------------------------------------------------------- /CSES_Problems/Weird_Algorithm/Problem.md: -------------------------------------------------------------------------------- 1 | LINK https://cses.fi/problemset/task/1068 -------------------------------------------------------------------------------- /CSES_Problems/Weird_Algorithm/solution.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | long long int num; //declaring number as long long integer 5 | scanf("%lld",&num); 6 | 7 | printf("%lld",num); 8 | 9 | while(num!=1) //loop works until number is not equals to 1 10 | { 11 | if(num%2==0) //if number is even 12 | num=num/2; //dividing the number by 2 13 | 14 | else //else number is odd 15 | num=(num*3)+1; //multiplying the number by 3 and then adding 1 to it 16 | 17 | printf(" %lld",num); //printing the result 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /CSES_Problems/ferris_wheel/problem.md: -------------------------------------------------------------------------------- 1 | Link to the problem statement : https://cses.fi/problemset/task/1090 2 | ------------------------------------------------------------------------------------------------------------------ 3 | Please visit the link for the problem statement and then try it youself, and then go for the solution. 4 | -------------------------------------------------------------------------------- /CodeChef_problems/A Problem on Sticks/Solution.cpp: -------------------------------------------------------------------------------- 1 | 2 | //author neha garg 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | int t;//number of test cases 8 | cin>>t; 9 | while(t--){ 10 | int n;//input the number of sticks 11 | cin>>n; 12 | int a[n],i;// for each valid i, the initial height of the stick in the i-th holder is A[i] 13 | sets; 14 | for( i=0;i>a[i]; 16 | } 17 | for( i=0;i 5 | using namespace std; 6 | int main( ) 7 | { 8 | int t;//to store the number of test cases 9 | cin>>t; 10 | for(int i=0;i>s; 14 | for(int j=0;j0 and t<=n: 11 | print(int(4*sqrtn+2)) #rectanglular formation 12 | elif t>n and t<=2*n: 13 | print(int(4*sqrtn+4)) #remaining cases 14 | -------------------------------------------------------------------------------- /CodeChef_problems/ATTND/problem.md: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/problems/ATTND -------------------------------------------------------------------------------- /CodeChef_problems/AVGPR/problem.md: -------------------------------------------------------------------------------- 1 | # Average Pair 2 | 3 | [LINK TO PROBLEM](https://www.codechef.com/problems/AVGPR) -------------------------------------------------------------------------------- /CodeChef_problems/Ada King/problem.md: -------------------------------------------------------------------------------- 1 | # Ada King 2 | 3 | [LINK TO PROBLEM](https://www.codechef.com/JULY20B/problems/ADAKING) 4 | 5 | 6 | -------------------------------------------------------------------------------- /CodeChef_problems/BINARR/problem.md: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/COVO2020/problems/BINARR/ 2 | -------------------------------------------------------------------------------- /CodeChef_problems/Bob and His Friends/problem.md: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/problems/BFRIEND/ 2 | -------------------------------------------------------------------------------- /CodeChef_problems/CARSELL/problem.md: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/problems/CARSELL/ -------------------------------------------------------------------------------- /CodeChef_problems/CENS20D/problem.md: -------------------------------------------------------------------------------- 1 | # Priya and AND 2 | 3 | Link : https://www.codechef.com/CENS2020/problems/CENS20D
4 |
5 | This question was asked in Codechef Code Ensemble contest held in August 2020. -------------------------------------------------------------------------------- /CodeChef_problems/CHEF AND CARD GAME/PROBLEM.MD.txt: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/JULY20B/problems/CRDGAME/ -------------------------------------------------------------------------------- /CodeChef_problems/CHEFEZQ/problem.md: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/problems/CHEFEZQ -------------------------------------------------------------------------------- /CodeChef_problems/CHEFINSQ/problem.md: -------------------------------------------------------------------------------- 1 | # Chef and interesting sequences 2 | 3 | [LINK TO PROBLEM](https://www.codechef.com/problems/CHEFINSQ) -------------------------------------------------------------------------------- /CodeChef_problems/CHEFK1/problem.md: -------------------------------------------------------------------------------- 1 | # Chef designed a network 2 | 3 | [LINK TO PROBLEM](https://www.codechef.com/problems/CHEFK1) -------------------------------------------------------------------------------- /CodeChef_problems/CHEFSTR1/problem.md: -------------------------------------------------------------------------------- 1 | 2 | problem link: https://www.codechef.com/JULY20B/problems/CHEFSTR1 3 | -------------------------------------------------------------------------------- /CodeChef_problems/CHEFSTR1/solution: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | 3 | #here i m taking the number of test cases 4 | 5 | for i in range(int (input())): 6 | 7 | n=int(input()) #chef takes the 'n' number of times to pluck a string 8 | 9 | l=list(map(int,input().split())) # here is the list 10 | 11 | s=0 12 | 13 | # here is the simple logic to get the total number of strings that was skipped while playing the song 14 | for i in range(1,len(l)): 15 | 16 | s=s+abs(l[i]-l[i-1])-1 # here i m just finding the total integer between two string and then count the sum for final answer 17 | 18 | print(s) 19 | -------------------------------------------------------------------------------- /CodeChef_problems/CHEFWED/Problem.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.codechef.com/AUG20B/problems/CHEFWED 2 | 3 | Level : Easy - Medium 4 | 5 | Tags : Dynamic Programming 6 | -------------------------------------------------------------------------------- /CodeChef_problems/CHFICRM/Problem.md: -------------------------------------------------------------------------------- 1 | # Chef and Icecream 2 | 3 | [LINK TO PROBLEM](https://www.codechef.com/JUNE20B/problems/CHFICRM) -------------------------------------------------------------------------------- /CodeChef_problems/CHFINTRO/problem.md: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/problems/CHFINTRO -------------------------------------------------------------------------------- /CodeChef_problems/CHFINTRO/solution.cpp: -------------------------------------------------------------------------------- 1 | // The problem is very straight-forward. If rating of a contestant is equal to greater than threshold rating then print "Good boi", otherwise "Bad boi" 2 | 3 | #include // includes every standard library 4 | #define lli long long int 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ios_base::sync_with_stdio(false); // Speeds up the execution time 10 | cin.tie(NULL); 11 | 12 | lli n, thresholdRating, rating; 13 | cin >> n >> thresholdRating; 14 | 15 | while(n--) { 16 | cin >> rating; 17 | 18 | if(rating >= thresholdRating) { 19 | cout << "Good boi" << endl; 20 | } else { 21 | cout << "Bad boi" << endl; 22 | } 23 | } 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /CodeChef_problems/CHFNSWPS/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.codechef.com/JULY20B/problems/CHFNSWPS/ 2 | -------------------------------------------------------------------------------- /CodeChef_problems/CLLCM/problem.md: -------------------------------------------------------------------------------- 1 | #Chef vs Doof 2 | 3 | Link : https://www.codechef.com/COLE2020/problems/CLLCM/ -------------------------------------------------------------------------------- /CodeChef_problems/CLPNT/problem.md: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/COLE2020/problems/CLPNT/ 2 | -------------------------------------------------------------------------------- /CodeChef_problems/COVIDLQ/problem.md: -------------------------------------------------------------------------------- 1 | # COVID Pandemic and Long Queue 2 | 3 | Link : https://www.codechef.com/APRIL20B/problems/COVIDLQ/
4 |
5 | This question was asked in Codechef April Long Challenge 2020. -------------------------------------------------------------------------------- /CodeChef_problems/CRDGAME3/problem.md: -------------------------------------------------------------------------------- 1 | Problem link : https://www.codechef.com/AUG20B/problems/CRDGAME3/ 2 | -------------------------------------------------------------------------------- /CodeChef_problems/CSUM/problem.md: -------------------------------------------------------------------------------- 1 | Link : 2 | Level : Easy - Medium 3 | Topic : Upper Lower Bound Problem 4 | -------------------------------------------------------------------------------- /CodeChef_problems/CVDRUN/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.codechef.com/OCT20B/problems/CVDRUN 2 | 3 | Level : Easy - Medium 4 | -------------------------------------------------------------------------------- /CodeChef_problems/CVDRUN/solution.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | The logic is to run the program a minimum number of times, i.e. n times in order 3 | to check if the city of spread reaches the desired city 4 | 5 | Thus we run the loop and increment x by k over n iterations to check if it ever equals k 6 | 7 | If it does, we set an infect tag and print "YES" 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | int main() { 13 | int t; 14 | cin>>t; 15 | while(t--){ 16 | int n,x,y,k,infect=0; 17 | cin>>n>>k>>x>>y; 18 | int i = n; 19 | while(i--){ 20 | if(x == y){ 21 | cout<<"YES"< 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | // your code goes here 8 | int t, n, k, x, i; 9 | cin>>t; 10 | string s; 11 | while(t--) 12 | { 13 | s = ""; 14 | cin>>n>>k; //Taking Input of n = No. of distances and k = Chef's step length 15 | int x[n]; 16 | for(i=0;i>x[i]; //Taking Input distance of i'th path 19 | if(x[i]%k==0) //if the distance of i'th place is traversable then add 1 into the string s 20 | s = s+"1"; 21 | else 22 | s = s+"0"; //If the chef can not travel to i'th place then add 0 to the string 23 | } 24 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; //Input of number of testcases 7 | while(t--) 8 | { 9 | string s; 10 | cin>>s; //Input of a String containing x or y letters 11 | int i,c=0; 12 | //Calculating the maximum numbers of pairs formed 13 | for(i=0;i 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | unsigned int n, divisor, dividend; 8 | int count = 0; 9 | 10 | cin >> n >> divisor; 11 | for(int i = 0; i < n; i++) 12 | { 13 | cin >> dividend; //input k each iteration 14 | if(dividend % divisor == 0) //check if it is divisible 15 | count++; //output 16 | } 17 | cout << count; 18 | } -------------------------------------------------------------------------------- /CodeChef_problems/FIBEASY/problem.md: -------------------------------------------------------------------------------- 1 | # Easy Fibonacci 2 | 3 | [LINK TO PROBLEM](https://www.codechef.com/problems/FIBEASY) -------------------------------------------------------------------------------- /CodeChef_problems/FIBEASY/solution.py: -------------------------------------------------------------------------------- 1 | #Question Link 2 | #https://www.codechef.com/problems/FIBEASY 3 | t=int(input()) 4 | import math 5 | x=0 6 | y=1 7 | z=0 8 | a=[] 9 | a.append(x) #appending first two values 10 | a.append(y) 11 | for i in range(0,118): 12 | a.append((x+y)%10) #calculating first 120 values' last digit of the fibonacci series 13 | z=(x+y)%10 14 | x=y%10 15 | y=z%10 16 | def func(n): 17 | power=0 18 | while(n>0): 19 | n=n>>1 20 | power+=1 21 | return 2**(power-1) 22 | for tc in range(t): #fibonacci series last digits repeat after every 60 values hence we have used mod 60 23 | n=int(input()) 24 | 25 | print(a[(func(n)-1)%60]) 26 | 27 | 28 | -------------------------------------------------------------------------------- /CodeChef_problems/FINXOR/problem.md: -------------------------------------------------------------------------------- 1 |

Problem Link

2 | Problem Link = https://www.codechef.com/SEPT20B/problems/FINXOR 3 |
4 | Difficulty Level = Easy-Medium. 5 | -------------------------------------------------------------------------------- /CodeChef_problems/Factorial/problem.md: -------------------------------------------------------------------------------- 1 | # Factorial (FCTRL) 2 | 3 | [Link to problem](https://www.codechef.com/LRNDSA01/problems/FCTRL) 4 | -------------------------------------------------------------------------------- /CodeChef_problems/GCD operations/problem.md: -------------------------------------------------------------------------------- 1 | # PROBLEMLINK 2 | 3 | https://www.codechef.com/LTIME88B/problems/GCDOPS 4 | 5 | Level: Beginner -------------------------------------------------------------------------------- /CodeChef_problems/GCD operations/solution.cpp: -------------------------------------------------------------------------------- 1 | 2 | //It’s only possible if for all i,ai is divisible by bi,otherwise impossible. 3 | 4 | #include 5 | using namespace std; 6 | 7 | typedef long long ll; 8 | 9 | void solve(int tc = 0) { 10 | ll n, x; 11 | cin >> n; 12 | 13 | bool pos = 1; 14 | for (ll i = 0; i < n; i++) { 15 | cin >> x; 16 | pos &= ((i + 1) % x == 0); 17 | } 18 | 19 | cout << (pos ? "YES\n" : "NO\n"); 20 | } 21 | 22 | int main() { 23 | 24 | int tc = 1; 25 | cin >> tc; 26 | for (int t = 0; t < tc; t++) solve(t); 27 | } -------------------------------------------------------------------------------- /CodeChef_problems/ICPC_Selection/problem.md: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/PRACTICE/problems/ICPCSEL -------------------------------------------------------------------------------- /CodeChef_problems/KJCP02/problem.md: -------------------------------------------------------------------------------- 1 | # Second Year Pains 2 | 3 | Problem: [https://www.codechef.com/problems/KJCP02](https://www.codechef.com/problems/KJCP02) 4 | -------------------------------------------------------------------------------- /CodeChef_problems/LAPD/problem.md: -------------------------------------------------------------------------------- 1 | # Biladerin Idin 2 | 3 | [LINK TO PROBLEM](https://www.codechef.com/problems/LAPD) -------------------------------------------------------------------------------- /CodeChef_problems/LAPD/solution.py: -------------------------------------------------------------------------------- 1 | #Question Link 2 | #https://www.codechef.com/problems/LAPD 3 | mod=10**9+7 4 | for tc in range(int(input())): 5 | A,B,C=map(int,input().split()) #input the values 6 | 7 | ct=0 8 | for i in range(1,B+1): 9 | temp=0 10 | for j in range(1,A+1): 11 | for k in range(1,C+1): 12 | if(i*i<((j-1)*(k-1))): #checking for all values possible b^2CHEF AND DOLLS 2 | 3 | LINK : https://www.codechef.com/problems/MISSP 4 | -------------------------------------------------------------------------------- /CodeChef_problems/Minimum Insertions/problem.md: -------------------------------------------------------------------------------- 1 | # PROBLEMLINK 2 | 3 | https://www.codechef.com/COOK122B/problems/MININS 4 | 5 | Level: Easy -------------------------------------------------------------------------------- /CodeChef_problems/Multiple of 3/problem.md: -------------------------------------------------------------------------------- 1 | # Multiple of 3 (MULTHREE) 2 | 3 | [Link to problem](https://www.codechef.com/LRNDSA01/problems/MULTHREE) 4 | -------------------------------------------------------------------------------- /CodeChef_problems/POSAND/problem.md: -------------------------------------------------------------------------------- 1 | # Zaidtech 2 | 3 | ## Problem link 4 | 5 | https://www.codechef.com/OCT20B/problems/POSAND -------------------------------------------------------------------------------- /CodeChef_problems/POTATOES/Problem.md: -------------------------------------------------------------------------------- 1 | POTATOES 2 | 3 | Link to the Problem: 4 | https://www.codechef.com/problems/POTATOES -------------------------------------------------------------------------------- /CodeChef_problems/POTATOES/Solution.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | The problem is based on mathematical analysis and requires the knowledge of prime numbers. 3 | Though basic , but it helps understand a basic concept clearly. 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | int fun(int f) 9 | { 10 | for(int j=2;j*j<=(f);j++) //this contains the Main Logic ; j is traversed till sqrt of f 11 | { if(f%j==0) 12 | { 13 | return 0; 14 | } 15 | } 16 | return 1; 17 | } 18 | 19 | int main() 20 | { 21 | int t,x,y,z;//t denotes the number of test cases 22 | cin>>t; 23 | while(t--) 24 | { 25 | cin>>x>>y;z=1; 26 | while(fun(x+y+z)==0) 27 | {z++;} 28 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; // t is the no of test cases 7 | cin>>t; 8 | while(t--) 9 | { int n,q,i; 10 | cin>>n; // n is the length of pin 11 | if(n%2==0) // if n is even 12 | q=n/2; // q is the length of half string 13 | else q=(n-1)/2; // q is the length of half string 14 | cout<<1<<" "<<1; 15 | for(i=0;i 9 | using namespace std; 10 | 11 | int main() 12 | { 13 | long long int tc, ts, js, t, c; 14 | cin >> tc; 15 | while(tc--) 16 | { 17 | cin >> ts; 18 | t=ts; 19 | c=0; 20 | while(t%2==0) 21 | { 22 | c++; 23 | t=t/2; 24 | } 25 | c++; 26 | js=pow(2,c); 27 | c=ts/js; 28 | cout << c << endl; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /CodeChef_problems/UNITGCD/problem.md: -------------------------------------------------------------------------------- 1 | # Unit GCD 2 | 3 | [LINK TO PROBLEM](https://www.codechef.com/APRIL20B/problems/UNITGCD) -------------------------------------------------------------------------------- /CodeChef_problems/WATERMELON/PROBLEM.MD.txt: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/LTIME88B/problems/WATMELON 2 | -------------------------------------------------------------------------------- /CodeChef_problems/WATERMELON/SOLUTION.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | 7 | int t; 8 | cin>>t; 9 | 10 | while(t--) 11 | { 12 | int n,sum=0; 13 | cin>>n; 14 | int arr[n+2]; 15 | //i have taken an array with increased size because sometimes tight arrays throws bound error 16 | //and in this case it was 17 | 18 | for(int i=0;i> arr[i]; 20 | sum=sum+arr[i]; 21 | } 22 | //then i stored the sum of array elements in a variable sum 23 | //if it was greater or equal to zero the output says YES 24 | if(sum>=0){ 25 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, m, con=0; 6 | cin >> n >> m; //number of experienced participants and newbies that are present at the training session. 7 | 8 | while(n>0 & m>0){ 9 | if(n==1 && m==1) break; 10 | //see which one has the most members in each round to balance as much as possible 11 | if(m>n){ 12 | m-=2; 13 | n-=1; 14 | con++; 15 | } 16 | else{ 17 | n-=2; 18 | m-=1; 19 | con++; 20 | } 21 | 22 | } 23 | 24 | cout << con; 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Codeforces_problems/A. Team/problem.md: -------------------------------------------------------------------------------- 1 | # A. Team 2 | 3 | ## Educational Codeforces Round 143 (Rated for Div. 2) 4 | 5 | ## problem link : https://codeforces.com/contest/231/problem/A 6 | -------------------------------------------------------------------------------- /Codeforces_problems/A. Team/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | //Creation of vars 6 | int n, a, b, c, count = 0; 7 | //Take in input for n lines 8 | std::cin >> n; 9 | //Loop for n 10 | for (int i = 0; i < n; i++) 11 | { 12 | //Take in user input 13 | std::cin >> a; 14 | std::cin >> b; 15 | std::cin >> c; 16 | //If more than 2 are sure then they will do the problem 17 | if (a + b + c >= 2) 18 | //Increase problem count 19 | count++; 20 | } 21 | //Return problem count 22 | std::cout << count; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Codeforces_problems/ABBB/problem.md: -------------------------------------------------------------------------------- 1 | # ABBB 2 | 3 | ## Codeforces Raif Round 1 (Div. 1 + Div. 2) 4 | 5 | ## problem link : https://codeforces.com/contest/1428/problem/C 6 | -------------------------------------------------------------------------------- /Codeforces_problems/Balanced ArrayB/problem.md: -------------------------------------------------------------------------------- 1 | https://codeforces.com/contest/1343/problem/B -------------------------------------------------------------------------------- /Codeforces_problems/Bargain/problem.md: -------------------------------------------------------------------------------- 1 | # Bargain 2 | 3 | ## Codeforces Round #675 (Div. 2) 4 | 5 | ## problem link : http://codeforces.com/contest/1422/problem/C 6 | -------------------------------------------------------------------------------- /Codeforces_problems/Barrels/problem.md: -------------------------------------------------------------------------------- 1 | # Barrels 2 | 3 | ## Educational Codeforces Round 96 (Rated for Div. 2) 4 | 5 | ## problem link : https://codeforces.com/contest/1430/problem/B 6 | -------------------------------------------------------------------------------- /Codeforces_problems/Beautiful Matrix/problem.md: -------------------------------------------------------------------------------- 1 | https://codeforces.com/problemset/problem/263/A 2 | -------------------------------------------------------------------------------- /Codeforces_problems/Boy or Girl 236A/problem.md: -------------------------------------------------------------------------------- 1 | # Boy or Girl 2 | 3 | https://codeforces.com/contest/236/problem/A -------------------------------------------------------------------------------- /Codeforces_problems/Boy or Girl 236A/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | ios::sync_with_stdio(0);cin.tie(0); 7 | string s; 8 | cin >> s; 9 | // occur[i] = 1 if character('a' + i) occurs in s 10 | vector occur(26); 11 | for (char ch : s) { 12 | occur[ch - 'a'] = 1; 13 | } 14 | int cnt = 0; 15 | for (int i = 0; i < 26; i++) { 16 | if (occur[i] > 0) cnt++; 17 | } 18 | // if the number of distinct characters in the string is odd, then he is a male, otherwise she is a female 19 | if (cnt % 2 == 0) cout << "CHAT WITH HER!\n"; 20 | else cout << "IGNORE HIM!\n"; 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Codeforces_problems/CandiesA/problem.md: -------------------------------------------------------------------------------- 1 | https://codeforces.com/contest/1343/problem/A -------------------------------------------------------------------------------- /Codeforces_problems/CandiesA/solution.py: -------------------------------------------------------------------------------- 1 | ''' 2 | so for any n = x + 2x + 4x + ... + 2^(k-1)*x 3 | we can write n = x*(1 + 2 + 4 + ... 2^(k-1)) 4 | this can be again written as n = x*(2^k - 1) 5 | thus all we need to do is check if the given such number has any such factor that can be written as 2^k -1 6 | and divide n by it to get x. 7 | ''' 8 | 9 | 10 | for i in range(int(raw_input())): 11 | n = int(raw_input()) 12 | i =2 13 | while (True): 14 | if(n%(pow(2,i)-1) == 0): #if we have found a factor of the form 2^k -1 15 | print n/(pow(2,i) - 1) 16 | break 17 | i += 1 18 | if(i > 80): #if 2^i gets too large/ larger than the given constraints 19 | print -1 20 | break -------------------------------------------------------------------------------- /Codeforces_problems/Chef Monokarp/problem.md: -------------------------------------------------------------------------------- 1 | Educational Codeforces Round 97 2 | 3 | https://codeforces.com/contest/1437/problem/C 4 | -------------------------------------------------------------------------------- /Codeforces_problems/Common SubsequenceA/problem.md: -------------------------------------------------------------------------------- 1 | https://codeforces.com/contest/1382/problem/A -------------------------------------------------------------------------------- /Codeforces_problems/Common SubsequenceA/solution.py: -------------------------------------------------------------------------------- 1 | ''' 2 | If there exists a common subsequence of length k then it's garunteed the 3 | smallest length of the subsequence that exists is 1 and that 1 length subsequence 4 | can be any of the element of the subsequence 5 | thus we check if there are any common elements between the 2 given arrays using a dictionary. 6 | ''' 7 | 8 | for i in range(int(raw_input())): 9 | n,m = map(int,raw_input().split()) 10 | x = list(map(int,raw_input().split())) 11 | y = list(map(int,raw_input().split())) 12 | d = {} 13 | for i in x: 14 | d[i] = 1 15 | done = False 16 | for i in y: 17 | if(d.get(i, -1) != -1): 18 | print "YES" 19 | print 1, i 20 | done = True 21 | break 22 | if(not done): 23 | print "NO" -------------------------------------------------------------------------------- /Codeforces_problems/CowAndHaybales1307A/codeforces1307A.cpp: -------------------------------------------------------------------------------- 1 | //1307A Cow and Haybales 2 | //Contributed by Mohd Warid (waridrox) 3 | 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int t; 10 | cin >> t; 11 | while(t--) { 12 | //n = number of piles 13 | //d = number of days 14 | //maxamise a1 15 | int N,D; cin >> N >> D; 16 | int a[N+1]; 17 | for (int i = 1; i <= N; i++) 18 | { 19 | cin >> a[i]; 20 | } 21 | 22 | while (D--)//D = 5 4 3 2 1 23 | { //loop over D days -> 2 3 4 5 24 | for (int i=2;i<=N;i++) 25 | if (a[i]>0)//3>0|2>0 || 1 2 2 26 | { //move closest haybale over 27 | a[i]--; //3->2->1 28 | a[i-1]++;//0->1->2 1 2 1 2 29 | break; 30 | } 31 | } 32 | 33 | cout< 5 | using namespace std; 6 | 7 | int main() { 8 | int n,c; cin >> n >> c; 9 | int a[n]; 10 | int w1 = 0,w2 = 0; 11 | for (int i =0; i < n; i++) 12 | { 13 | cin >> a[i]; 14 | } 15 | 16 | for (int i = 0; i < n-1; i++) 17 | { 18 | int diff = a[i+1]-a[i]; 19 | if (diff <= c)//1 <= 1 20 | { 21 | w1++; 22 | } 23 | else if (diff > c)//2 > 1.2 > 1.2 > 1.2 > 1. 24 | { 25 | w1= 0;//w = 0. 26 | } 27 | } 28 | cout << w1+1; 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Codeforces_problems/Dice Tower/problem.md: -------------------------------------------------------------------------------- 1 | # Dice Tower 2 | 3 | ## codeforces Round Global round 6 B 4 | 5 | ## problem link : https://codeforces.com/problemset/problem/1266/B 6 | 7 | 8 | -------------------------------------------------------------------------------- /Codeforces_problems/Divide It A/problem.md: -------------------------------------------------------------------------------- 1 | http://codeforces.com/contest/1176/problem/A -------------------------------------------------------------------------------- /Codeforces_problems/Divide It A/solution.py: -------------------------------------------------------------------------------- 1 | # We follow a greedy strategy to divide the number as much as we can. 2 | # If there it is a multiple of 3, we introduce a factor of 2 so we can remove it completely in 2 counts. 3 | # If there it is a multiple of 5, we introduce a factor of 4 so we can remove it completely in 3 counts. 4 | for i in range(int(input())): 5 | num = int(input()) 6 | count = 0 7 | while(num%2 == 0): 8 | num = num//2 9 | count+=1 10 | while(num%3 == 0): 11 | num = num//3 12 | count+=2 13 | while(num%5 == 0): 14 | num = num//5 15 | count+=3 16 | if(num!=1): 17 | print(-1) 18 | else: 19 | print(count) -------------------------------------------------------------------------------- /Codeforces_problems/Dominant Piranha/problem.md: -------------------------------------------------------------------------------- 1 | problem link: https://codeforces.com/contest/1433/problem/C -------------------------------------------------------------------------------- /Codeforces_problems/Domino Piling/problem.md: -------------------------------------------------------------------------------- 1 | problem link: https://codeforces.com/problemset/problem/50/A -------------------------------------------------------------------------------- /Codeforces_problems/Domino Piling/solution.py: -------------------------------------------------------------------------------- 1 | m, n = map(int, input().split()) #taking m and n as input 2 | 3 | #since each small domino is of size 2x1, it can be said that the total number of dominos which can be fitted 4 | #is equal to MxN divided by 2, but this can give a decimal answer. What the question asks for is the maximum 5 | #number of complete squares. 6 | #converting our decimal answer to int gives us the integer value of that number, leaving out the fractional part. 7 | #thus we typecast our solution to int. 8 | print(int(m*n/2)) -------------------------------------------------------------------------------- /Codeforces_problems/Drazil and Factorial/problem.md: -------------------------------------------------------------------------------- 1 | Link: https://codeforces.com/contest/515/problem/C -------------------------------------------------------------------------------- /Codeforces_problems/Dreamoon and WIFI/problem.md: -------------------------------------------------------------------------------- 1 | link : https://codeforces.com/contest/476/problem/B 2 | -------------------------------------------------------------------------------- /Codeforces_problems/Equalize/problem.md: -------------------------------------------------------------------------------- 1 | # Equalize 2 | 3 | ## Manthan, Codefest 18 (rated, Div. 1 + Div. 2) 4 | 5 | ## problem link : https://codeforces.com/contest/1037/problem/C 6 | -------------------------------------------------------------------------------- /Codeforces_problems/Equalize/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, con=0; 6 | cin >> n; //length of the strings a and b. 7 | string a, b; 8 | int c[n]; 9 | 10 | cin >> a >> b; 11 | 12 | for(int i=0; i 6 | using namespace std; 7 | int main() 8 | { 9 | long long t,a,b,c,d,i,j; 10 | cin>>t; 11 | while(t--){ 12 | cin>>a>>b>>c; 13 | d=a+b+c; 14 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | vector v; 6 | 7 | v.push_back(1); 8 | v.push_back(1); 9 | 10 | for(int i=2 ;i<21;i++){ 11 | v.push_back(v[i-2]+v[i-1]); 12 | } 13 | 14 | // V is vector that store the first 20 fibonacci number 15 | 16 | int n; 17 | 18 | cin>>n; 19 | 20 | // Now we return the wanted number in position n 21 | cout<= 2 in our final array as all numbers are even. 5 | for tt in range(int(input())): 6 | n = int(input()) 7 | l = list(map(int, input().split())) 8 | odd = [] 9 | even = [] 10 | for i in range(len(l)): 11 | if(l[i]%2==0): 12 | even.append(i+1) 13 | else: 14 | odd.append(i+1) 15 | ptrOdd = 0 16 | ptrEven = 0 17 | for i in range(n-1): 18 | if(ptrOdd 3 | using namespace std; 4 | 5 | int main(){ 6 | int n, max=0; 7 | cin >> n; //number of houses in the capital of Berland 8 | int a[n], b[n]; 9 | 10 | for(int i=0; i> a[i]; //number of floors in the i-th house 12 | } 13 | 14 | b[n-1]=0; 15 | max=a[n-1]; //consider that initially the largest house is the one on the right most 16 | for(int i=n-2; i>=0; i--){ //for from right to left 17 | if(a[i]<=max) b[i]=max-a[i]+1; //if the current house is smaller than the one considered to be bigger so far 18 | else b[i]=0, max=a[i]; //if the current house is bigger than all the previous ones 19 | } 20 | 21 | for(int i=0; i0): 8 | s+=num%10 9 | num = num//10 10 | return s 11 | 12 | for i in range(int(input())): 13 | n = int(input()) 14 | l = list(map(int, input().split())) 15 | x_0 = 0 16 | x_1 = 0 17 | x_2 = 0 18 | for i in range(n): 19 | temp = sum_of(l[i]) 20 | if(temp%3 == 0): 21 | x_0 += 1 22 | elif((temp-1)%3 == 0): 23 | x_1 += 1 24 | else: 25 | x_2+=1 26 | temp = min(x_1, x_2) 27 | count = x_0 + temp 28 | x_1-=temp 29 | x_2-=temp 30 | count += x_1//3 31 | count += x_2//3 32 | print(count) -------------------------------------------------------------------------------- /Codeforces_problems/Mike And Cellphones 689A/problem.md: -------------------------------------------------------------------------------- 1 | # Mike and Cellphone 2 | ## Problem Link - https://codeforces.com/contest/689/problem/A -------------------------------------------------------------------------------- /Codeforces_problems/Minimum Ternary String/problem.md: -------------------------------------------------------------------------------- 1 | # Minimum Ternary String 2 | 3 | ## Educational Codeforces Round 47 (Rated for Div. 2) 4 | 5 | ## problem link : https://codeforces.com/contest/1009/problem/B 6 | -------------------------------------------------------------------------------- /Codeforces_problems/New Theatre Square/problem.md: -------------------------------------------------------------------------------- 1 | # JOE is on TV! 2 | 3 | ## codeforces Round 614 D2 B 4 | 5 | ## problem link : https://codeforces.com/problemset/problem/1293/B 6 | 7 | 8 | -------------------------------------------------------------------------------- /Codeforces_problems/New Theatre Square/solution.cpp: -------------------------------------------------------------------------------- 1 | // This question is greedy problem. 2 | 3 | // variable are t-eliminated rivals s-is the remaining opponent. 4 | 5 | // First of all we have to think how t/s becomes more rewarding. 6 | // so the optimal solution is to eliminate one at a time. 7 | // so t becomes 1 8 | 9 | 10 | #include 11 | using namespace std; 12 | 13 | void Solve(int n) { 14 | double ans = 0; 15 | for (int i=1; i<=n; i++) ans += 1.0 / i; 16 | cout << fixed << setprecision(12) << ans << endl; 17 | } 18 | 19 | int main() { 20 | ios_base::sync_with_stdio(0); cin.tie(NULL); 21 | int n; 22 | cin>>n; 23 | Solve(n); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Codeforces_problems/Next Round/problem.md: -------------------------------------------------------------------------------- 1 | problem link: https://codeforces.com/problemset/problem/158/A -------------------------------------------------------------------------------- /Codeforces_problems/Next Round/solution.py: -------------------------------------------------------------------------------- 1 | n, k = map(int, input().split()) #taking number of elements and k as input 2 | x = [] 3 | x = [int(x) for x in input().split()] #inputting elements in list x[] 4 | 5 | count = 0 #initialising count to 0 6 | 7 | for i in x: 8 | if i>=x[k-1] and i>0: #checking if score is greater than kth place score and positive 9 | count=count+1 10 | 11 | print(count) #final count of participants advancing to next round -------------------------------------------------------------------------------- /Codeforces_problems/Nice Matrix/problem.md: -------------------------------------------------------------------------------- 1 | problem link: https://codeforces.com/contest/1422/problem/B -------------------------------------------------------------------------------- /Codeforces_problems/Number Game/problem.md: -------------------------------------------------------------------------------- 1 | ## https://codeforces.com/problemset/problem/1370/C -------------------------------------------------------------------------------- /Codeforces_problems/Numbers on Whiteboard/problem.md: -------------------------------------------------------------------------------- 1 | problem link : https://codeforces.com/contest/1430/problem/C -------------------------------------------------------------------------------- /Codeforces_problems/Remove Smallest/Problem.md: -------------------------------------------------------------------------------- 1 | ## Remove Smallest 2 | 3 | ## Codeforces Div-3 1399-A 4 | 5 | ## Problem Link: https://codeforces.com/contest/1399/problem/A -------------------------------------------------------------------------------- /Codeforces_problems/Restore the Permutation by Merger/Problem.md: -------------------------------------------------------------------------------- 1 | ## Restore the Permutation by Merger 2 | 3 | ## Codeforces Div-3 1385-B 4 | 5 | ## Problem Link: https://codeforces.com/contest/1385/problem/B -------------------------------------------------------------------------------- /Codeforces_problems/Reverse Binary Strings/problem.md: -------------------------------------------------------------------------------- 1 | # Reverse Binary Strings 2 | 3 | problem Link: https://codeforces.com/contest/1437/problem/B -------------------------------------------------------------------------------- /Codeforces_problems/RockPaperScissors/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link : http://codeforces.com/problemset/problem/1426/E 4 | -------------------------------------------------------------------------------- /Codeforces_problems/Semifinals/problem.md: -------------------------------------------------------------------------------- 1 | # Semifinals 2 | 3 | ## Codeforces Round #222 (Div. 2) 4 | 5 | ## problem link : https://codeforces.com/contest/378/problem/B 6 | -------------------------------------------------------------------------------- /Codeforces_problems/Songs Compression/problem.md: -------------------------------------------------------------------------------- 1 | # Songs Compression 2 | 3 | ## Codeforces Round #501 (Div. 3) 4 | 5 | ## problem link : https://codeforces.com/contest/1015/problem/C 6 | -------------------------------------------------------------------------------- /Codeforces_problems/Songs Compression/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | long long int n, m, x=0, y=0, aux=0, con=0; 6 | cin >> n >> m; 7 | long long int a[n], b[n], c[n]; 8 | for(int i=0; i> a[i] >> b[i]; 10 | x+=a[i]; //x=total song size initially 11 | y+=b[i]; //y=total song size after compression 12 |   13 | c[i]=a[i]-b[i]; //difference in music size after compression and initially 14 | } 15 | 16 | if(y>m){ 17 | cout << "-1"; 18 | return 0; 19 | } 20 | else{ 21 | sort(c, c+n); //Put the difference in ascending order 22 | n--; 23 | while(x>m){ 24 | x-=c[n]; 25 | n--; 26 | con++; 27 | } 28 | } 29 | 30 | cout << con; 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Codeforces_problems/Subset Mex/problem.md: -------------------------------------------------------------------------------- 1 | #Subset Mex - Round 670 2 | 3 | link- https://codeforces.com/contest/1406/problem/A -------------------------------------------------------------------------------- /Codeforces_problems/Tavas and Nafas/Problem.md: -------------------------------------------------------------------------------- 1 | https://codeforces.com/contest/535/problem/A 2 | -------------------------------------------------------------------------------- /Codeforces_problems/Tavas and SaDDas/problem.md: -------------------------------------------------------------------------------- 1 | Codeforces Round #299 (Div. 2) 2 | B. Tavas and SaDDas 3 | link https://codeforces.com/problemset/problem/535/B 4 | -------------------------------------------------------------------------------- /Codeforces_problems/Team/problem.md: -------------------------------------------------------------------------------- 1 | problem link https://codeforces.com/problemset/problem/231/A -------------------------------------------------------------------------------- /Codeforces_problems/Team/solution.py: -------------------------------------------------------------------------------- 1 | n = int(input()) #taking number of test cases as input 2 | sures = [] #list for appending sureties of all 3 3 | count = 0 4 | for i in range(0,n): 5 | x = [int(x) for x in input().split()] #taking 3 elements as list together and appending in list sures[] 6 | sures.append(x) 7 | if x.count(1)>=2: #if more than 2 people are sure, that means the problem can be solved 8 | count=count+1 9 | 10 | print(count) #printing final count on how many problems can be solved -------------------------------------------------------------------------------- /Codeforces_problems/Telephone Number 1167A/problem.md: -------------------------------------------------------------------------------- 1 | # Telephone number 2 | 3 | https://codeforces.com/contest/1167/problem/A -------------------------------------------------------------------------------- /Codeforces_problems/Ternary Sequence1401B/problem.md: -------------------------------------------------------------------------------- 1 | Problem link: https://codeforces.com/contest/1401/problem/B 2 | -------------------------------------------------------------------------------- /Codeforces_problems/Theatre Square/problem.md: -------------------------------------------------------------------------------- 1 | #Codeforces Beta Round #1 2 | 3 | link- https://codeforces.com/contest/1/problem/A -------------------------------------------------------------------------------- /Codeforces_problems/Towers/problem.md: -------------------------------------------------------------------------------- 1 | # Towers 2 | 3 | ## Codeforces Round #274 (Div. 2) 4 | 5 | ## problem link : https://codeforces.com/contest/479/problem/B 6 | -------------------------------------------------------------------------------- /Codeforces_problems/TurnTheRectangles/problem.md: -------------------------------------------------------------------------------- 1 | https://codeforces.com/gym/234626/problem/E -------------------------------------------------------------------------------- /Codeforces_problems/Two Platforms/problem.md: -------------------------------------------------------------------------------- 1 | # Two Platforms 2 | 3 | ## problem link : http://codeforces.com/contest/1409/problem/E 4 | -------------------------------------------------------------------------------- /Codeforces_problems/Vanya and Lanterns/problem.md: -------------------------------------------------------------------------------- 1 | # Vanya and Lanterns 2 | 3 | ## Codeforces Round #280 (Div. 2) 4 | 5 | ## problem link : https://codeforces.com/contest/492/problem/B -------------------------------------------------------------------------------- /Codeforces_problems/Vasya and String/problem.md: -------------------------------------------------------------------------------- 1 | # Vasya and String 2 | 3 | ## Codeforces Round #354 (Div. 2) 4 | 5 | ## problem link : https://codeforces.com/contest/676/problem/C -------------------------------------------------------------------------------- /Codeforces_problems/Way too long words/problem.md: -------------------------------------------------------------------------------- 1 | problem link: https://codeforces.com/problemset/problem/71/A -------------------------------------------------------------------------------- /Codeforces_problems/Way too long words/solution.py: -------------------------------------------------------------------------------- 1 | n = int(input()) #input number of test cases 2 | 3 | words = [] #list of all test cases 4 | 5 | for i in range(0,n): 6 | word = str(input()) 7 | words.append(word) #appending test cases in list 8 | 9 | for word in words: 10 | if len(word)<=10: #if word length less than 10 11 | print(word) 12 | else: 13 | print(word[0]+str((len(word)-2))+word[len(word)-1]) #if greater than 10, print first letter, number of letters in between, and last letter -------------------------------------------------------------------------------- /Codeforces_problems/XXXXX/problem.md: -------------------------------------------------------------------------------- 1 | https://codeforces.com/contest/1364/problem/A 2 | -------------------------------------------------------------------------------- /Codeforces_problems/Yet Another Bookshelf 1433B/problem.md: -------------------------------------------------------------------------------- 1 | # Yet Another Bookshelf 2 | 3 | https://codeforces.com/problemset/problem/1433/B 4 | -------------------------------------------------------------------------------- /Codeforces_problems/Yet Another Bookshelf 1433B/solution.py: -------------------------------------------------------------------------------- 1 | T=int(input()) # Taking T for T test cases 2 | 3 | 4 | while T!=0 : 5 | n=int(input()) # Taking n :- no. of inputs in array 6 | v=[int(i) for i in input().split()] # Taking array as input of 0's and 1's and coverting to int 7 | """ 8 | Counting number of zeroes which are between the extreme 1's at the ends 9 | for example : 10 | 1001 : 2 11 | 001010100 : 2 12 | 13 | """ 14 | 15 | ind=[i for i in range(n) if v[i]==1] 16 | least=min(ind) 17 | most=max(ind) 18 | count=0 19 | for i in v[least:most]: 20 | if i==0: 21 | count+=1 22 | print(count) 23 | 24 | T-=1 25 | -------------------------------------------------------------------------------- /Codeforces_problems/Young Physicist/problem.md: -------------------------------------------------------------------------------- 1 | ## https://codeforces.com/problemset/problem/69/A -------------------------------------------------------------------------------- /Codeforces_problems/Young Physicist/solution.py: -------------------------------------------------------------------------------- 1 | 2 | n = int(input()) # no. of vectors 3 | sumx = 0 4 | sumy =0 5 | sumz = 0 6 | 7 | # take coordinates of vector and add it to the 8 | # sum of respective coordinate 9 | for i in range(n): 10 | x,y,z = map(int, input().split()) 11 | sumx += x 12 | sumy += y 13 | sumz += z 14 | 15 | 16 | if sumx == 0 and sumy == 0 and sumz == 0 : 17 | print("YES") # A body is at equilibrium if sum of all vectors is zero 18 | else: 19 | print("NO") 20 | -------------------------------------------------------------------------------- /Codeforces_problems/Zero Remainder Sum/problem.md: -------------------------------------------------------------------------------- 1 | #Zero Remainder Summ - Round 667 Div3 2 | https://codeforces.com/contest/1433/problem/F 3 | -------------------------------------------------------------------------------- /Codeforces_problems/buttons/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://codeforces.com/contest/268/problem/B 2 | -------------------------------------------------------------------------------- /Codeforces_problems/decoding/problem.md: -------------------------------------------------------------------------------- 1 | # Decoding 2 | 3 | ## Codeforces Round #386 (Div. 2) 4 | 5 | ## problem link : https://codeforces.com/contest/746/problem/B 6 | -------------------------------------------------------------------------------- /Codeforces_problems/police recruits/problem.md: -------------------------------------------------------------------------------- 1 | https://codeforces.com/contest/427/problem/A -------------------------------------------------------------------------------- /Codeforces_problems/sum of digits/problem.md: -------------------------------------------------------------------------------- 1 | # Sum of digits 2 | 3 | ## Codeforces Beta Round #79 (Div. 2 Only) 4 | 5 | ## problem link : https://codeforces.com/contest/102/problem/B 6 | -------------------------------------------------------------------------------- /Codeforces_problems/watermelon/problem.md: -------------------------------------------------------------------------------- 1 | https://codeforces.com/contest/4/problem/A -------------------------------------------------------------------------------- /Codeforces_problems/watermelon/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | #define fo(i,n) for(i=0;i>n; 9 | //took input from the user 10 | //if the number entered is two it cannot be divided into even natural numbers 11 | //thats why its a corner case and needs to be handled differently 12 | if(n==2){ 13 | cout<<"NO"< array[n]) { 5 | larger.push(array[i]); 6 | } 7 | } 8 | const min = Math.min(...larger); 9 | return array.indexOf(min); 10 | 11 | //larger contains the elements of array which are larger then array[n] 12 | //min is the minimum of larger's elements 13 | //the function returns with the min's index in array 14 | } 15 | 16 | console.log(leastLarger([-1, -6, -4, -7, 9, -3, 6, 0], 2)); 17 | 18 | // n = 2 19 | // array[n] = -4 20 | // larger = [-1, 9, -3, 6, 0] 21 | // min = -3 22 | // array[5] = -3, so array.indexOf(min) = 5 -------------------------------------------------------------------------------- /Codewars_problems/Probabilities for Sums in Rolling Cubic Dice/problem.md: -------------------------------------------------------------------------------- 1 | https://www.codewars.com/kata/56f78a42f749ba513b00037f 2 | -------------------------------------------------------------------------------- /Codewars_problems/Traffic light/problem.md: -------------------------------------------------------------------------------- 1 | # Thinkful - Logic Drills: Traffic light 2 | 3 | You're writing code to control your town's traffic lights. You need a function to handle each change from `green`, to `yellow`, to `red`, and then to `green` again. 4 | 5 | Complete the function that takes a string as an argument representing the current state of the light and returns a string representing the state the light should change to. 6 | 7 | For example, `update_light('green')` should return `'yellow'`. 8 | 9 | [Problem link](https://www.codewars.com/kata/58649884a1659ed6cb000072) 10 | -------------------------------------------------------------------------------- /Codewars_problems/Traffic light/solution.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Used two ternary operators to evaluate the state of traffic light as string argument 3 | * to display the light it will change next. e.g. enter 'yellow' and it will display 4 | * 'red' as the next light. 5 | */ 6 | 7 | function updateLight(current) { 8 | 9 | return current === 'green' ? 'yellow' : current === 'yellow' ? 'red' : 'green'; 10 | 11 | } 12 | 13 | -------------------------------------------------------------------------------- /Codewars_problems/Where my Anagrams At/problem.md: -------------------------------------------------------------------------------- 1 | https://www.codewars.com/kata/523a86aa4230ebb5420001e1/train/javascript 2 | -------------------------------------------------------------------------------- /Codewars_problems/Where my Anagrams At/solution.js: -------------------------------------------------------------------------------- 1 | function anagrams(word, words) { 2 | let anagrams = []; 3 | const sortedWord = word.split("").sort().join(""); 4 | for (const w of words) { 5 | if ( 6 | w.length === word.length && // if the length is not same, then there is no need to check for sorted condition 7 | w.split("").sort().join("") === sortedWord 8 | ) { 9 | anagrams.push(w); 10 | } 11 | } 12 | return anagrams; 13 | } 14 | -------------------------------------------------------------------------------- /Exercism_Problems/space_age/problem.md: -------------------------------------------------------------------------------- 1 | PROBLEM LINK: https://exercism.io/my/solutions/a6ec72789c5b470887327465b4a7faa2 -------------------------------------------------------------------------------- /GeeksForGeeks/Arya_Long_String/Problem.md: -------------------------------------------------------------------------------- 1 | PROBLEM LINK: https://practice.geeksforgeeks.org/problems/aryas-long-string/0 -------------------------------------------------------------------------------- /GeeksForGeeks/Blum Integer/problem.md: -------------------------------------------------------------------------------- 1 | Problem: https://www.geeksforgeeks.org/blum-integer/ -------------------------------------------------------------------------------- /GeeksForGeeks/Blum Integer/solution.py: -------------------------------------------------------------------------------- 1 | # Function to cheek if number is Blum Integer 2 | def isBlumInteger(n): 3 | 4 | prime = [True]*(n + 1) 5 | 6 | # to store prime numbers from 2 to n 7 | i = 2 8 | while (i * i <= n): 9 | 10 | if (prime[i] == True) : 11 | 12 | # Update all multiples of p 13 | for j in range(i * 2, n + 1, i): 14 | prime[j] = False 15 | i = i + 1 16 | 17 | # to check if the given odd integer is Blum Integer or not 18 | for i in range(2, n + 1) : 19 | if (prime[i]) : 20 | 21 | # checking the factors are of 4t+3 form or not 22 | if ((n % i == 0) and 23 | ((i - 3) % 4) == 0): 24 | q = int(n / i) 25 | return (q != i and prime[q] 26 | and (q - 3) % 4 == 0) 27 | 28 | return False 29 | 30 | n = int(input()) 31 | if (isBlumInteger(n)): 32 | print("Yes") 33 | else: 34 | print("No") -------------------------------------------------------------------------------- /GeeksForGeeks/Count_of_Vessels/assets/out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vishruth-S/CompetitiveCode/28a3ea13d744b799b628ee71ef6db82e8d9e3fd3/GeeksForGeeks/Count_of_Vessels/assets/out.png -------------------------------------------------------------------------------- /GeeksForGeeks/Count_of_Vessels/assets/out2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vishruth-S/CompetitiveCode/28a3ea13d744b799b628ee71ef6db82e8d9e3fd3/GeeksForGeeks/Count_of_Vessels/assets/out2.png -------------------------------------------------------------------------------- /GeeksForGeeks/Detect Loop in Linked List/problem.md: -------------------------------------------------------------------------------- 1 | https://practice.geeksforgeeks.org/problems/detect-loop-in-linked-list/1 -------------------------------------------------------------------------------- /GeeksForGeeks/Kadane's Algorithm/Problem.md: -------------------------------------------------------------------------------- 1 | ## Question 2 | Kadane's Algorithm https://practice.geeksforgeeks.org/problems/kadanes-algorithm/0 3 | -------------------------------------------------------------------------------- /GeeksForGeeks/Kadane's Algorithm/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; //no. of testcases 7 | while(t!=0) 8 | { 9 | int n; 10 | cin>>n; //enter size of array 11 | int i, e=0, f=INT_MIN, arr[n]; 12 | for(i=0; i>arr[i]; //take array input 14 | for(i=0; i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n, inp; 7 | int x=0, y=0; 8 | 9 | cin >> n; 10 | 11 | /* 12 | we capture the input numbers and add them in the variable x, 13 | and add the odd numbers, we compare the two sums and find the missing number. 14 | */ 15 | for(int i=1; i> inp; 18 | x+=inp; 19 | }else{ 20 | 21 | y+=i; 22 | } 23 | } 24 | cout << y - x <Pizza Confusion 2 | Link: https://www.hackerearth.com/practice/algorithms/sorting/bubble-sort/practice-problems/algorithm/pizza-confusion/description/ 3 | -------------------------------------------------------------------------------- /HackerEarth_problems/Prasanjeet verma and his sorrow/Problem.md: -------------------------------------------------------------------------------- 1 | # link :- 2 | https://www.hackerearth.com/practice/data-structures/advanced-data-structures/trie-keyword-tree/practice-problems/algorithm/prasanjeet-verma-and-his-sorrow/ 3 | -------------------------------------------------------------------------------- /HackerEarth_problems/RepeatedKTimes/problem.md: -------------------------------------------------------------------------------- 1 | problem found at https://www.hackerearth.com/practice/algorithms/searching/linear-search/practice-problems/algorithm/repeated-k-times/ 2 | -------------------------------------------------------------------------------- /HackerEarth_problems/RepeatedKTimes/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int arrSize; 6 | cin >> arrSize; 7 | 8 | // fill array with the inputted elements 9 | int arr[arrSize]; 10 | for (int i=0; i < arrSize; i++){ 11 | cin >> arr[i]; 12 | } 13 | 14 | 15 | // fill occurrences array with # of each int present in arr 16 | int occurrences[arrSize] = { 0 }; 17 | for (int i=0; i < arrSize; i++){ 18 | occurrences[arr[i]]++; 19 | } 20 | 21 | int k; 22 | cin >> k; // # of occurences we're looking for 23 | 24 | int answer = -1; 25 | 26 | // the first time a number has the desired # of occurrences, 27 | // save that number in our "answer" variable 28 | for (int i=0; i < arrSize; i++){ 29 | if (occurrences[i] == k && answer == -1) 30 | answer = i; 31 | } 32 | 33 | cout << answer; 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /HackerEarth_problems/Rotation/problem.md: -------------------------------------------------------------------------------- 1 | problem found at: https://www.hackerearth.com/practice/algorithms/string-algorithm/basics-of-string-manipulation/practice-problems/algorithm/rotation-1-38ecf5a7/ -------------------------------------------------------------------------------- /HackerEarth_problems/Rotation/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,count=0; 8 | string s,t; 9 | cin>>n; 10 | cin>>s; 11 | cin>>t; 12 | if(s.compare(t) ==0) // check if both the strings are same or not 13 | cout<<0<=0;i--) 17 | 18 | { 19 | count++; 20 | s.erase(0,1); // remove start character from string s 21 | t.erase(i,1); // remove last character from string t 22 | if(s.compare(t)==0) // if botth the strings are same then break 23 | break; 24 | } 25 | cout<e-maze-in 2 | Link : https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/e-maze-in-1aa4e2ac/ 3 | -------------------------------------------------------------------------------- /Hackerrank_problems/2D Arrays/problem.md: -------------------------------------------------------------------------------- 1 | # LINK 2 | https://www.hackerrank.com/challenges/30-2d-arrays/problem 3 | -------------------------------------------------------------------------------- /Hackerrank_problems/2D Arrays/solution.java: -------------------------------------------------------------------------------- 1 | package com.company; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | 6 | // Creating 2-D array 7 | int[][] array = {{10,20,30},{40,50,60}}; 8 | // Extracting elements using for-each loop 9 | for (int[] i : array){ 10 | for (int j : i){ 11 | System.out.println("Element in array is : " + j); 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Hackerrank_problems/3D_Surface_Area/Problem.md: -------------------------------------------------------------------------------- 1 | Link https://www.hackerrank.com/challenges/3d-surface-area/problem 2 | -------------------------------------------------------------------------------- /Hackerrank_problems/A Personalized Echo/problem.md: -------------------------------------------------------------------------------- 1 | ## Write a Bash script which accepts name 2 | 3 | as input and displays a greeting: "Welcome (name)" 4 | 5 | ### Input Format 6 | 7 | One line, containing a name. 8 | 9 | ### Output Format 10 | 11 | One line: "Welcome (name)" (quotation marks excluded). 12 | The evaluation will be case-sensitive. 13 | 14 | ### Sample Input 0 15 | 16 | Dan 17 | 18 | ### Sample Output 0 19 | 20 | Welcome Dan 21 | 22 | ### Sample Input 1 23 | 24 | Prashant 25 | 26 | ### Sample Output 1 27 | 28 | Welcome Prashant 29 | 30 | Link: https://www.hackerrank.com/challenges/bash-tutorials---a-personalized-echo/problem 31 | -------------------------------------------------------------------------------- /Hackerrank_problems/A Personalized Echo/solution.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/bash 2 | # read input with read command and prompt with echo 3 | read name 4 | echo "Welcome "$name 5 | -------------------------------------------------------------------------------- /Hackerrank_problems/Angry Professor/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.hackerrank.com/challenges/angry-professor/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Angry Professor/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int T; 6 | cin >> T; 7 | int x; 8 | int N, k, sum; 9 | for (int i = 0; i < T; i++) { 10 | sum = 0; 11 | cin >> N >> k; 12 | for(int i = 0; i < N; i++) { 13 | cin >> x; 14 | // if negative then add to sum 15 | if (x <= 0) { 16 | sum++; 17 | } 18 | } 19 | // if sum 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | 13 | 14 | int main() 15 | { 16 | int a[10000],n,count=0,max=0; 17 | 18 | scanf("%d",&n); //enter the integer 19 | while(n){ 20 | if(n%2!=0) //if n is divisible by 2 then count will increase by 1 21 | 22 | count++; 23 | else 24 | count=0; //else count will remain 0 25 | if(max>=1; 28 | } 29 | printf("%d",max); //value stored in max is printed. 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Hackerrank_problems/Birthday_chocolate/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://www.hackerrank.com/challenges/the-birthday-bar/problem?h_r=internal-search 2 | -------------------------------------------------------------------------------- /Hackerrank_problems/Bitwise_operator/PROBLEM.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/bitwise-operators-in-c/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Cats and a Mouse/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://www.hackerrank.com/challenges/cats-and-a-mouse/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Check_LeapYear/solution.py: -------------------------------------------------------------------------------- 1 | #Author : @Aashrut 2 | 3 | def is_leap(year): 4 | # We initialize the variable leap to False, so that if it doesn't pass all condition then it can return False. 5 | leap = False 6 | 7 | # conditions for leap year 8 | # If year is divided by 4, then it is leap year 9 | if (year%4)==0: 10 | leap=True 11 | # but if it is also evenly divided by 100, then it is not a leap year 12 | if (year%100)==0: 13 | leap=False 14 | # but also if it is evenly divided by 400, then it is leap year 15 | if (year%400)==0: 16 | leap=True 17 | 18 | return leap 19 | 20 | ''' 21 | To test the function run the below lines: 22 | year = 1990 23 | print(is_leap(year)) # Outputs False 24 | ''' 25 | -------------------------------------------------------------------------------- /Hackerrank_problems/Chocolate Feast/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.hackerrank.com/challenges/chocolate-feast/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Circular Array Rotation/problem.md: -------------------------------------------------------------------------------- 1 | ### Problem Link: https://www.hackerrank.com/challenges/circular-array-rotation 2 | -------------------------------------------------------------------------------- /Hackerrank_problems/Common Child/problem.md: -------------------------------------------------------------------------------- 1 | Problem link - https://www.hackerrank.com/challenges/common-child/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Compare The Triplets/problem.md: -------------------------------------------------------------------------------- 1 | LINK https://www.hackerrank.com/challenges/compare-the-triplets/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Comparing Numbers/solution.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/bash 2 | # accept two numbers with each read command and compare nums with conditional operators 3 | read num1 4 | read num2 5 | if [[ $num1 > $num2 ]] 6 | then 7 | echo X is greater than Y 8 | elif [[ $num1 < $num2 ]] 9 | then 10 | echo X is less than Y 11 | else 12 | echo X is equal to Y 13 | fi 14 | -------------------------------------------------------------------------------- /Hackerrank_problems/CreditCardValid/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.hackerrank.com/challenges/validating-credit-card-number/problem 2 | 3 | Level : Medium 4 | -------------------------------------------------------------------------------- /Hackerrank_problems/Currency-formatter/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/java-currency-formatter/problem 2 | -------------------------------------------------------------------------------- /Hackerrank_problems/Cut The Sticks/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: 2 | https://www.hackerrank.com/challenges/cut-the-sticks/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Cut The Sticks/soloution.py: -------------------------------------------------------------------------------- 1 | def calc(l,n): 2 | z=[] 3 | q=[n] # initially all sticks are present 4 | while(len(l) > 0): 5 | for i in l: 6 | if(i-min(l)>0):#append all sticks greter than minimum in arr 7 | z.append(i-min(l)) 8 | 9 | q.append(len(z)) #len(z) = number of visible sticks 10 | l=z #l gets updated with z as sticks are being removed 11 | z=[] 12 | return q 13 | n=int(input()) #no of sticks 14 | l= [int(x) for x in input().split()] 15 | for i in calc(l,n): 16 | if(i!=0): 17 | print(i) 18 | -------------------------------------------------------------------------------- /Hackerrank_problems/Cycle Detection/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/detect-whether-a-linked-list-contains-a-cycle/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Day 29 Bitwise AND Problem/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | Link https://www.hackerrank.com/challenges/30-bitwise-and/problem 3 | -------------------------------------------------------------------------------- /Hackerrank_problems/Day_Of_The_Programmer/solution.rb: -------------------------------------------------------------------------------- 1 | #@Input: A year of type numeric 2 | 3 | #@Brief: 4 | # The problem with the calendar resides in the year 1918, where the calendar was changed 5 | # So we have this breakpoint as an exception 6 | # Then we proceed to check the leap years in Gregorian and Julian 7 | # Else we will return 13.09. + given year. 8 | 9 | #@Output: A string with the day of programer 10 | 11 | 12 | def day_of_programmer(year) 13 | if year == 1918 14 | return '26.09.1918' 15 | elsif ((year <= 1917) & (year%4 == 0)) or ((year > 1918) & (year%400 == 0 or ((year%4 == 0) & (year%100 != 0)))) 16 | return '12.09.'+year.to_s 17 | else 18 | return '13.09.'+year.to_s 19 | end 20 | end 21 | 22 | puts (day_of_programmer(2017)) -------------------------------------------------------------------------------- /Hackerrank_problems/Designer PDF Viewer/solution.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | int a[26],max=0,ascii; 7 | char c[10]; 8 | 9 | for(int i=0;i<26;i++) 10 | scanf("%d",&a[i]); //reading inputs and storing them in the integer array 11 | 12 | scanf("%s",c); //reading the string 13 | 14 | int len=strlen(c); //calculating length 15 | 16 | for(int i=0;imax) 21 | max=a[ascii]; //stores the maximum height 22 | 23 | } 24 | 25 | printf("%d",len*max); //printing the result 26 | return 0; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Hackerrank_problems/Divisible Sum Pairs/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.hackerrank.com/challenges/divisible-sum-pairs/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Diwali Lights/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/diwali-lights/problem 2 | -------------------------------------------------------------------------------- /Hackerrank_problems/DrawingBook/Solution.py: -------------------------------------------------------------------------------- 1 | 2 | n = int(input().strip()) 3 | p = int(input().strip()) 4 | if p <= n: 5 | print(min(p // 2, n // 2 - p // 2)) 6 | 7 | 8 | # working 9 | # the minimum numbers of pages to turn can be achieved either moving pages from the front or from the back 10 | # either way pages will increment or decrement in progression of 2 11 | # therefore minimum to any page will be , if starting from the front side (p // 2) 12 | 13 | # you can calculate the number of pages from the back side too using the same logic 14 | # but a faster way is to subtract (p // 2) from total number of pages 15 | 16 | # the answer to the problem therefore is min between both values you get [front and back] -------------------------------------------------------------------------------- /Hackerrank_problems/DrawingBook/Solution2.py: -------------------------------------------------------------------------------- 1 | #Author : @shashankseth01 2 | #Simple solution for drawing book in python language 3 | 4 | n = int(input("Enter the number of pages")) 5 | p = int(input("Destination Page")) 6 | print (min(p/2,n/2-p/2)) # if we open the book from front then destination page will take p/2 turn overs. 7 | # if we open the book form back then destination page will take n/2-p/2 turn overs. 8 | 9 | -------------------------------------------------------------------------------- /Hackerrank_problems/DrawingBook/problem.md: -------------------------------------------------------------------------------- 1 | Problem link: https://www.hackerrank.com/challenges/drawing-book/problem 2 | Difficulty: Easy -------------------------------------------------------------------------------- /Hackerrank_problems/DrawingBook/solution.js: -------------------------------------------------------------------------------- 1 | function pageCount(bookSize, target){ 2 | return Math.min( //pick whichever has the lowest value between 3 | Math.floor(target/2)+1, //number of pages from beginning 4 | Math.floor((bookSize-target)/2)+1 //number of pages from end 5 | ) 6 | } -------------------------------------------------------------------------------- /Hackerrank_problems/ElectronicShop/Problem.md: -------------------------------------------------------------------------------- 1 | Link: https://www.hackerrank.com/challenges/electronics-shop/problem 2 | -------------------------------------------------------------------------------- /Hackerrank_problems/EquilibriumPoint in array/problem.md: -------------------------------------------------------------------------------- 1 | Question/Problem link: 2 | https://www.hackerrank.com/contests/one-last-timeagain/challenges/equilibrium-point-2 -------------------------------------------------------------------------------- /Hackerrank_problems/Extra Long Factorials/problem.md: -------------------------------------------------------------------------------- 1 | # question 2 | ## https://www.hackerrank.com/challenges/extra-long-factorials/problem 3 | -------------------------------------------------------------------------------- /Hackerrank_problems/Fibonacci-Series/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/fibonacci-modified/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Find Merge Point of Two Lists/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/find-the-merge-point-of-two-joined-linked-lists/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Find_a_point/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/find-point/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Find_digits/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/find-digits/problem -------------------------------------------------------------------------------- /Hackerrank_problems/FizzBuzz/Problem.md: -------------------------------------------------------------------------------- 1 | Link: https://www.hackerrank.com/challenges/fizzbuzz/problem 2 | -------------------------------------------------------------------------------- /Hackerrank_problems/FizzBuzz/Solution2.py: -------------------------------------------------------------------------------- 1 | def fizzbuzz(x): 2 | """FizzBuzz challenge 3 | scan through 1 to 100 and tell which numbers are fizz, buzz, or fizzbuzz 4 | fizz - a number divisible by 3 5 | buzz - a number divisible by 5 6 | fizzbuzz - a number divisible by 5 and 3 7 | """ 8 | for i in range(x): 9 | i += 1 10 | if i % 3 == 0 and i % 5 == 0: 11 | print("fizzbuzz") 12 | elif i % 3 == 0: 13 | print("fizz") 14 | elif i % 5 == 0: 15 | print("buzz") 16 | else: 17 | print(i) 18 | 19 | 20 | fizzbuzz(100) 21 | -------------------------------------------------------------------------------- /Hackerrank_problems/FizzBuzz/solution.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Used one liner if else statements 3 | print FizzBuzz if number is divisible by 3 and 5 4 | print Fizz if number is divisible by 3 5 | print Buzz if number is divisible by 5 6 | otherwise print number as it is 7 | ''' 8 | if __name__ == '__main__': 9 | result = ["FizzBuzz" if number%3 == 0 and number%5 ==0 else ("Fizz" if number%3==0 else ("Buzz" if number%5 == 0 else number)) for number in range(1, 101)] 10 | for i in result: 11 | print(i) 12 | -------------------------------------------------------------------------------- /Hackerrank_problems/Getting started with conditionals/problem.md: -------------------------------------------------------------------------------- 1 | Read in one character from STDIN. 2 | If the character is 'Y' or 'y' display "YES". 3 | If the character is 'N' or 'n' display "NO". 4 | No other character will be provided as input. 5 | 6 | Input Format 7 | 8 | One character 9 | 10 | Constraints 11 | 12 | The character will be from the set {yYnN}. 13 | 14 | Output Format 15 | 16 | echo YES or NO to STDOUT. 17 | 18 | Sample Input 19 | 20 | y 21 | 22 | Sample Output 23 | 24 | YES 25 | 26 | Link: https://www.hackerrank.com/challenges/bash-tutorials---getting-started-with-conditionals/problem 27 | -------------------------------------------------------------------------------- /Hackerrank_problems/Getting started with conditionals/solution.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/bash 2 | # accept a string and check if it is n,N or Y,y,return "NO" or "YES" respectively. 3 | read string 4 | if [[ "$string" == "n" ]] || [[ $string == "N" ]] 5 | then 6 | echo NO 7 | elif [[ "$string" == "Y" ]] || [[ "$string" == "y" ]] 8 | then 9 | echo YES 10 | fi 11 | -------------------------------------------------------------------------------- /Hackerrank_problems/Hackfest2020/GameOfMaximization/problem.md: -------------------------------------------------------------------------------- 1 | Link 2 | 3 | https://www.hackerrank.com/contests/hackerrank-hackfest-2020/challenges/stones-piles -------------------------------------------------------------------------------- /Hackerrank_problems/Hackfest2020/StrictlyIncreasingSequence/problem.md: -------------------------------------------------------------------------------- 1 | Link 2 | 3 | https://www.hackerrank.com/contests/hackerrank-hackfest-2020/challenges/strictly-increasing-sequence -------------------------------------------------------------------------------- /Hackerrank_problems/Halloween Party/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/halloween-party/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Halloween Party/solution.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import os 4 | import sys 5 | 6 | def halloweenParty(k): 7 | """ 8 | first square the amount times 9 | then divide it with the 2 squares (or 4) 10 | *don't forget to round down the float 11 | """ 12 | return int((k*k)/4) 13 | 14 | if __name__ == '__main__': 15 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 16 | 17 | t = int(input()) 18 | 19 | for t_itr in range(t): 20 | k = int(input()) 21 | 22 | result = halloweenParty(k) 23 | 24 | fptr.write(str(result) + '\n') 25 | 26 | fptr.close() 27 | -------------------------------------------------------------------------------- /Hackerrank_problems/Hotel Price/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/hotel-prices/problem -------------------------------------------------------------------------------- /Hackerrank_problems/If-Else/problem.md: -------------------------------------------------------------------------------- 1 | # Problem Link 2 | 3 | https://www.hackerrank.com/challenges/java-if-else/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Intro to Conditional Statements/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | link : https://www.hackerrank.com/challenges/30-conditional-statements/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Intro to Conditional Statements/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | 7 | int main() 8 | { 9 | int N; 10 | cin >> N; 11 | cin.ignore(numeric_limits::max(), '\n'); // Used to clear the stack of input 12 | if(N % 2 != 0 ){ //if N is odd 13 | cout<<"Weird"; 14 | } 15 | else if(N % 2 == 0 && N >= 2 && N <= 5){ //if N is even and between 2 and 5 16 | cout<<"Not Weird"; 17 | } 18 | else if(N%2 == 0 && N>=6 && N<= 20){ //if N is even and between 6 and 20 19 | cout<<"Weird"; 20 | } 21 | else{cout<<"Not Weird";} //if N is even and greater than 20 22 | 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Hackerrank_problems/Is This a Binary Search Tree/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/is-binary-search-tree/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Journey to the moon/problem.md: -------------------------------------------------------------------------------- 1 | Problem link - https://www.hackerrank.com/challenges/journey-to-the-moon/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Jumping on the Clouds/problem.md: -------------------------------------------------------------------------------- 1 | Problem link: https://www.hackerrank.com/challenges/jumping-on-the-clouds/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Jumping on the Clouds/solution.py: -------------------------------------------------------------------------------- 1 | 2 | def jumpingOnClouds(c): 3 | 4 | count = -1 # initialize 5 | i = 0 6 | while i < len(c): # iterate till the end of cloud 7 | count += 1 8 | if i < len(c) - 2 and c[i + 2] == 0: # will check next jump on cloud 9 | i += 1 10 | i += 1 # increment 11 | return count # returns output 12 | 13 | if __name__ == '__main__': 14 | 15 | n = int(input()) # total number of clouds 16 | c = list(map(int, input().rstrip().split())) # n space-separated binary integers describing clouds 17 | result = jumpingOnClouds(c) # Calling Method 18 | print(result) # Output -------------------------------------------------------------------------------- /Hackerrank_problems/Keyword_Transposition_Cipher/problem.md: -------------------------------------------------------------------------------- 1 | Problem link: https://www.hackerrank.com/challenges/keyword-transposition-cipher/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Let's Review/problem.md: -------------------------------------------------------------------------------- 1 | # question 2 | ## https://www.hackerrank.com/challenges/30-review-loop/problem 3 | -------------------------------------------------------------------------------- /Hackerrank_problems/Library Fine/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://www.hackerrank.com/challenges/library-fine/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Making Anagrams/Problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link https://www.hackerrank.com/challenges/ctci-making-anagrams/problem 4 | -------------------------------------------------------------------------------- /Hackerrank_problems/Mars Exploration/problem.md: -------------------------------------------------------------------------------- 1 |

Mars Exploration

2 | Link : https://www.hackerrank.com/challenges/mars-exploration/problem 3 | -------------------------------------------------------------------------------- /Hackerrank_problems/Mars Exploration/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | int main() 5 | { 6 | string s;//to store the input string 7 | getline(cin, s); 8 | 9 | int l=s.length( );//length of string 10 | int k=0;//count of letters changed 11 | for(int i=0;i int(h): 8 | print(math.ceil(h)) 9 | 10 | else: 11 | print("%.0f" % h) 12 | -------------------------------------------------------------------------------- /Hackerrank_problems/Modified Kaprekar Numbers/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://www.hackerrank.com/challenges/kaprekar-numbers/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Modified Kaprekar Numbers/solution.py: -------------------------------------------------------------------------------- 1 | def check(i): 2 | sq = str(i**2) # squaring the input 3 | le = len(str(i)) # calculating the length 4 | r = sq[-le:] # extracting the right hand part 5 | l = sq[:-le] or '0' # extracting the left hand part 6 | return sum(map(int,(l,r)))==i # sum the right and left part and checking if equals to the input number 7 | 8 | def kaprekarNumbers(p, q): 9 | return [i for i in range(p,q+1) if check(i)] 10 | 11 | p = int(input()) 12 | q = int(input()) 13 | print(*kaprekarNumbers(p, q) or ["INVALID RANGE"]) -------------------------------------------------------------------------------- /Hackerrank_problems/Non_divisible_Subset/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | link : https://www.hackerrank.com/challenges/non-divisible-subset/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Operators/Problem.md: -------------------------------------------------------------------------------- 1 | # Problem : Operators 2 | 3 | Problem link : https://www.hackerrank.com/challenges/30-operators/problem 4 | Question : Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as tip), and tax percent (the percentage of the meal price being added as tax) for a meal, find and print the meal's total cost. 5 | 6 | Note: Be sure to use precise values for your calculations, or you may end up with an incorrectly rounded result! 7 | -------------------------------------------------------------------------------- /Hackerrank_problems/Organizing_container_of_balls/Problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://www.hackerrank.com/challenges/organizing-containers-of-balls/problem 4 | -------------------------------------------------------------------------------- /Hackerrank_problems/Pairs/problem.md: -------------------------------------------------------------------------------- 1 | # Problem - Pairs 2 | 3 | - Difficulty - Medium 4 | - Points - 50 5 | 6 | - Link - https://www.hackerrank.com/challenges/pairs/problem 7 | -------------------------------------------------------------------------------- /Hackerrank_problems/Picking Numbers/problem.md: -------------------------------------------------------------------------------- 1 | ### Problem Link: https://www.hackerrank.com/challenges/picking-numbers 2 | -------------------------------------------------------------------------------- /Hackerrank_problems/Queue using Two Stacks/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/queue-using-two-stacks/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Recursion_Fibonacci_Numbers/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://www.hackerrank.com/challenges/ctci-fibonacci-numbers/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Repeated String/Problem.md: -------------------------------------------------------------------------------- 1 | ## Problem Statement Link 2 | 3 | https://www.hackerrank.com/challenges/repeated-string/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Restaurant/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/restaurant/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Reverse Game/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/reverse-game/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Reverse Game/solution.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 | # since there's no def function you need to make a loop by yourself to keep asking input 13 | # for each testcase 14 | t = int(input()) 15 | for i in range(t): 16 | nk = input().split() 17 | n = int(nk[0]) 18 | k = int(nk[1]) 19 | 20 | # it can be seen from the pattern in the example case 21 | # you just need to check whether it is less than n-k-1 or not 22 | # and print it two times k plus one if it is less 23 | # or print two times n-k-1 24 | if (k < n-k-1 ): 25 | print ((k*2)+1) 26 | else : 27 | print(2*(n-k-1)) 28 | -------------------------------------------------------------------------------- /Hackerrank_problems/Reverse Linked List/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/reverse-a-linked-list/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Road and Libraries/problem.md: -------------------------------------------------------------------------------- 1 | Problem link - https://www.hackerrank.com/challenges/torque-and-development/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Sales by Match/Problem.md: -------------------------------------------------------------------------------- 1 | ## Problem Statement 2 | 3 | https://www.hackerrank.com/challenges/sock-merchant/problem 4 | 5 | -------------------------------------------------------------------------------- /Hackerrank_problems/Sam and substrings/problem.md: -------------------------------------------------------------------------------- 1 | Problem link - https://www.hackerrank.com/challenges/sam-and-substrings/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Sequence Equation/Problem.md: -------------------------------------------------------------------------------- 1 | # Sequence Equation 2 | https://www.hackerrank.com/challenges/permutation-equation/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Sequence Equation/Solution_4.py: -------------------------------------------------------------------------------- 1 | l1=[] 2 | ##Input number of elements in list 3 | n=int(input()) 4 | ##Input the elements in the list 5 | l1=list(map(int,input().split())) 6 | ## Create a new list l2 to store the index(from 1 to number of elements in list1) of elements of list 1 7 | l2=[i for i in range(1,n+1)] 8 | ##Run a for loop from 1 till the length of list 1(l1) 9 | for i in range(1,n+1): 10 | ##Find the Index of ith element of list (l1) 11 | x=l1.index(i) 12 | ##print(x) 13 | ##Now find which element is located at that index in list (l2) 14 | y=l2[x] 15 | ##Now find the index of this element (y) in list (l1) 16 | ##Finally print the element located at that index in list (l2) 17 | print(l2[l1.index(y)]) 18 | -------------------------------------------------------------------------------- /Hackerrank_problems/Service Lane/solution.c: -------------------------------------------------------------------------------- 1 | //author: Soham Sarkar 2 | 3 | #include 4 | 5 | int main(){ 6 | 7 | int n,t,width[100000],i,j,k,m,p; 8 | scanf("%d %d",&n,&t); //read the n and t 9 | 10 | for(p=0;p 2 | 3 | #### Sherlock and valid strings
4 | 5 | Difficulty : 6 | Medium
7 | [Link](https://www.hackerrank.com/challenges/sherlock-and-valid-string/problem) -------------------------------------------------------------------------------- /Hackerrank_problems/Sherlock_and_Permutation/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/sherlock-and-permutations/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Simple Text Editor/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/simple-text-editor/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Simple Text Editor/solution.py: -------------------------------------------------------------------------------- 1 | """Use a stack/list 'previous_states' to save the 2 | last state of the string before apply the operation. 3 | """ 4 | if __name__ == '__main__': 5 | S = '' 6 | previous_states = [] 7 | total_operations = int(input()) 8 | for _ in range(total_operations): 9 | operation_line = input().split() 10 | operation = int(operation_line[0]) 11 | if operation == 1: 12 | previous_states.append(S) 13 | w = operation_line[1] 14 | S += w 15 | if operation == 2: 16 | previous_states.append(S) 17 | k = int(operation_line[1]) 18 | S = S[:-k] 19 | if operation == 3: 20 | k = int(operation_line[1]) 21 | print(S[k-1]) 22 | if operation == 4: 23 | S = previous_states.pop() 24 | -------------------------------------------------------------------------------- /Hackerrank_problems/Solve_me_first/Problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link https://www.hackerrank.com/challenges/solve-me-first/problem 4 | -------------------------------------------------------------------------------- /Hackerrank_problems/Solve_me_first/Solution2.py: -------------------------------------------------------------------------------- 1 | #Author : @shashankseth01 2 | #Simple solution for Solve_me_first in python language 3 | 4 | a=int(input("First integer")) #input first integer 5 | b=int(input("Second integer")) #input second integer 6 | print(a+b) #Calculate and print sum 7 | -------------------------------------------------------------------------------- /Hackerrank_problems/Solve_me_first/solution.java: -------------------------------------------------------------------------------- 1 | // Logic 2 | // The required solution can be obtained by simply getting the integers values and adding the two values 3 | // Scanner is used to get the input value as integer, return value must be specified to get the results of the sum of two integers 4 | 5 | public class Solution { 6 | 7 | static int solveMeFirst(int a, int b) { 8 | return a+b; //returning sum 9 | } 10 | 11 | public static void main(String[] args) { 12 | Scanner in = new Scanner(System.in); 13 | int a; 14 | a = in.nextInt(); 15 | int b; 16 | b = in.nextInt(); 17 | int sum; 18 | sum = solveMeFirst(a, b); 19 | System.out.println(sum); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Hackerrank_problems/Solve_me_first/solve_me_first_solution2: -------------------------------------------------------------------------------- 1 | def solveMeFirst(a,b): # this function take 2 parameters and return addition of both number. 2 | return a + b 3 | 4 | 5 | num1 = int(input()) # taking input from user and storing into num1 variable. 6 | num2 = int(input()) # taking input from user and storing into num2 variable. 7 | res = solveMeFirst(num1,num2) # store the result into res variable. 8 | 9 | print(res) # print the result. 10 | -------------------------------------------------------------------------------- /Hackerrank_problems/Sparse Array/Problem.md: -------------------------------------------------------------------------------- 1 | Link: https://www.hackerrank.com/challenges/sparse-arrays/problem 2 | -------------------------------------------------------------------------------- /Hackerrank_problems/Summing_n_series/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/summing-the-n-series/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Summing_n_series/solution.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import os 4 | import sys 5 | 6 | def summingSeries(n): 7 | """ 8 | the formula it's self if tn = n^2 - (n-1)^2 9 | sn = t1+ t2 + ... + tn 10 | but if we look it closely we can make a shortcut by 11 | just returning the last n^2 12 | 13 | next it's said that it's needed to be mod(10^9 + 7) 14 | """ 15 | return (n**2)%(10**9 + 7) 16 | 17 | if __name__ == '__main__': 18 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 19 | 20 | t = int(input()) 21 | 22 | for t_itr in range(t): 23 | n = int(input()) 24 | 25 | result = summingSeries(n) 26 | 27 | fptr.write(str(result) + '\n') 28 | 29 | fptr.close() 30 | -------------------------------------------------------------------------------- /Hackerrank_problems/Time_Conversion/problem.md: -------------------------------------------------------------------------------- 1 | LINK https://www.hackerrank.com/challenges/time-conversion/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Time_Conversion/time_conversion.py: -------------------------------------------------------------------------------- 1 | # Taking input of time and splitting that into hour, minutes, and seconds. 2 | h, m, s = input().split(':') 3 | 4 | # s[-2:] is to get status of time i.e. AM or PM. 5 | 6 | if s[-2:] == 'AM' and h == '12': 7 | ## manage 12 AM hour. 8 | print(f'{0}{0}:{m}:{s[:-2]}') 9 | 10 | elif s[-2:] == 'AM': 11 | ## manage day time. 12 | print(f'{h}:{m}:{s[:-2]}') 13 | 14 | elif s[-2:] == 'PM' and h == '12': 15 | ## manage 12 PM hour. 16 | print(f'{h}:{m}:{s[:-2]}') 17 | 18 | elif s[-2:] == 'PM': 19 | ## manage night time. 20 | print(f'{int(h)+12}:{m}:{s[:-2]}') 21 | -------------------------------------------------------------------------------- /Hackerrank_problems/Time_In_Words/Problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://www.hackerrank.com/challenges/the-time-in-words/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Tower_of_Hanoi_Recursion/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://www.hackerrank.com/contests/launchpad-1-winter-challenge/challenges/shift-plates 4 | -------------------------------------------------------------------------------- /Hackerrank_problems/Triangle_Quest/problem.md: -------------------------------------------------------------------------------- 1 | # PROBLEMLINK 2 | 3 | https://www.hackerrank.com/challenges/python-quest-1/problem 4 | -------------------------------------------------------------------------------- /Hackerrank_problems/Triangle_Quest/solution.py: -------------------------------------------------------------------------------- 1 | # Used the fact that 9ths as decimals have repeating digits (1/9=.11111, 2/9=.22222) with powers of 10 to get the correct length of each number. 2 | # Completed in 2 lines as required by problem. 3 | for i in range(1,int(input())): 4 | print((10**(i)//9)*i) 5 | -------------------------------------------------------------------------------- /Hackerrank_problems/Triangle_Quest_2/Problem.md: -------------------------------------------------------------------------------- 1 | LINK https://www.hackerrank.com/challenges/triangle-quest-2/problem -------------------------------------------------------------------------------- /Hackerrank_problems/Triangle_Quest_2/Solution.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | A positive integer N. 4 | The task is to print a palindromic triangle of size N. 5 | 6 | For example, a palindromic triangle of size is: 7 | 8 | 1 9 | 121 10 | 12321 11 | 1234321 12 | 123454321 13 | ''' 14 | 15 | #Here in for loop the range from 1 to input+1 16 | #It prints the number raised to power 10 and then divide by 9 and the whole result is having power 2. 17 | #Then the palindrome integer is printed. 18 | n = int(input()) 19 | 20 | for i in range(1, n+1): 21 | #to get the palindrome integer triangle i must be raised as power to 10 then divided by 9 22 | #and stored in vaiable a. 23 | 24 | a = int((10**i/9)) 25 | 26 | #a is squared and then the number becomes palindromic and printed. 27 | print(a**2) 28 | -------------------------------------------------------------------------------- /Hackerrank_problems/Variablesize_array/problem.md: -------------------------------------------------------------------------------- 1 | Link to the problem https://www.hackerrank.com/challenges/variable-sized-arrays/problem -------------------------------------------------------------------------------- /Hackerrank_problems/array-reversal/problem.md: -------------------------------------------------------------------------------- 1 | # Array Reversal 2 | ### Description 3 | Given an array, of size , reverse it. 4 | 5 | Example: If array, arr=[1,2,3,4,5] , after reversing it, the array should be, arr=[5,4,3,2,1] . 6 | 7 | ### Link Hacker Rank 8 | https://www.hackerrank.com/challenges/reverse-array-c/problem -------------------------------------------------------------------------------- /Hackerrank_problems/array_left_rotation/Problem.md: -------------------------------------------------------------------------------- 1 | Link : https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=arrays -------------------------------------------------------------------------------- /Hackerrank_problems/array_left_rotation/array_left_rotation.py: -------------------------------------------------------------------------------- 1 | n , k = list(map(eval , input().split())) # n = Size of array , k = rotating number 2 | lis = list(map(eval , input().split())) # Initial array 3 | 4 | rotated_array = [] 5 | 6 | # Initially appending 0's to rotated array 7 | for i in range(len(lis)): 8 | rotated_array.append(0) 9 | 10 | # CORE LOGIC 11 | # Here i have used modulos operator to create a cyclic nature 12 | for i in range(len(lis)): 13 | rotated_array[i] = lis[(i + k) % len(lis)] 14 | 15 | # Printing the final rotated array 16 | for i in range(len(lis)): 17 | print(rotated_array[i] , end = " ") 18 | -------------------------------------------------------------------------------- /Hackerrank_problems/counting_valleys/problem.md: -------------------------------------------------------------------------------- 1 | Link https://www.hackerrank.com/challenges/counting-valleys/problem -------------------------------------------------------------------------------- /Hackerrank_problems/day_of_the_programmer/problem.md: -------------------------------------------------------------------------------- 1 | Link https://www.hackerrank.com/challenges/day-of-the-programmer/problem -------------------------------------------------------------------------------- /Hackerrank_problems/diagonal-difference/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/diagonal-difference/problem -------------------------------------------------------------------------------- /Hackerrank_problems/kangaroo/Problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link https://www.hackerrank.com/challenges/kangaroo/problem 4 | -------------------------------------------------------------------------------- /Hackerrank_problems/kangaroo/solution.py: -------------------------------------------------------------------------------- 1 | # Logic: 2 | # The required result is simply the solution of the equations 3 | # x1 + y*v1 = x2 + y*v2 (where y is the number of jumps) 4 | # which is same as checking if (x1-x2)%(v2-v1)==0 5 | 6 | 7 | def kangaroo(x1, v1, x2, v2): 8 | return "YES" if (v1 > v2) and not (x2 - x1) % (v2 - v1) else "NO" 9 | 10 | 11 | if __name__ == '__main__': 12 | 13 | # input 14 | x1V1X2V2 = input().split() 15 | 16 | x1 = int(x1V1X2V2[0]) 17 | 18 | v1 = int(x1V1X2V2[1]) 19 | 20 | x2 = int(x1V1X2V2[2]) 21 | 22 | v2 = int(x1V1X2V2[3]) 23 | 24 | result = kangaroo(x1, v1, x2, v2) 25 | 26 | print(result) 27 | -------------------------------------------------------------------------------- /Hackerrank_problems/loops/Solution1.py: -------------------------------------------------------------------------------- 1 | 2 | if __name__ == '__main__': 3 | n = int(input()) 4 | 5 | for integer in range(n): #run the loop for n times. 6 | square = integer * integer # multiply integer * integer which will give you square of number and store it into square variable. 7 | 8 | print(square) # print the result. 9 | -------------------------------------------------------------------------------- /Hackerrank_problems/loops/problem.md: -------------------------------------------------------------------------------- 1 | #problem 2 | https://www.hackerrank.com/challenges/python-loops/problem -------------------------------------------------------------------------------- /Hackerrank_problems/loops/solution.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | n = int(input()) #Enter an integer 3 | for i in range(0,n): #the loop will iterate from 0 to (n-1) 4 | print(i*i) #it will print the square of each number from 0 to (n-1) 5 | -------------------------------------------------------------------------------- /Hackerrank_problems/staircase/problem.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/staircase/problem -------------------------------------------------------------------------------- /Hackerrank_problems/staircase/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | // Complete the staircase function below. 7 | void staircase(int n) { 8 | //first loop is used to make rows 9 | for (int i = 0 ; i =0; j--){ 12 | 13 | if (j==i){ 14 | cout << ("#"); 15 | } 16 | else if(j> n; 31 | cin.ignore(numeric_limits::max(), '\n'); 32 | 33 | staircase(n); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /InterviewBit_problems/BinaryTree_PreorderTraversal/Problem.md: -------------------------------------------------------------------------------- 1 | //Problem link : 2 | 3 | A very useful concept to search as well as other operations in Binary trees. 4 | 5 | https://www.interviewbit.com/problems/preorder-traversal/ 6 | -------------------------------------------------------------------------------- /InterviewBit_problems/CP_BinaryTree/Problem.md: -------------------------------------------------------------------------------- 1 | Symmetric Binary Trees 2 | 3 | 4 | Link To Problem: 5 | 6 | https://www.interviewbit.com/problems/symmetric-binary-tree/ -------------------------------------------------------------------------------- /InterviewBit_problems/EncodingBased problem/Problem.md: -------------------------------------------------------------------------------- 1 | Rearrange Array 2 | 3 | This is a very tricky CP as well as Interview problem and is based on mathematical Encoding . 4 | 5 | Link to the Problem : 6 | https://www.interviewbit.com/problems/rearrange-array/ -------------------------------------------------------------------------------- /InterviewBit_problems/LeastCommonAncestor/problem.md: -------------------------------------------------------------------------------- 1 | ## Problem is two find out the least common ancestor of the given two nodes in a tree. 2 | 3 | #### Problem Link: 4 | - https://www.interviewbit.com/problems/least-common-ancestor/ -------------------------------------------------------------------------------- /InterviewBit_problems/Math_Section/Problem.md: -------------------------------------------------------------------------------- 1 | Power of Two Integers 2 | 3 | LINK TO THE PROBLEM: 4 | https://www.interviewbit.com/problems/power-of-two-integers/ 5 | -------------------------------------------------------------------------------- /InterviewBit_problems/Math_Section/Problem_2.md: -------------------------------------------------------------------------------- 1 | Trailing Zeroes in Factorial 2 | 3 | This is a very important interview problem and is based on mathematical analysis. 4 | 5 | Link to the Problem : 6 | https://www.interviewbit.com/problems/trailing-zeros-in-factorial/ -------------------------------------------------------------------------------- /InterviewBit_problems/Math_Section/Solution_2.cpp: -------------------------------------------------------------------------------- 1 | /*Though the problems seems to be complex , yet its an easy one!! 2 | Just follow the pattern of when zeroes do repeat in factorials , and there you go! 3 | */ 4 | 5 | //Below is the required function , short and efficient!! 6 | 7 | int Solution::trailingZeroes(int A) 8 | { 9 | int s=0; 10 | while(A!=0) 11 | { 12 | A/=5; 13 | s+=A; 14 | } 15 | return s; 16 | } 17 | -------------------------------------------------------------------------------- /InterviewBit_problems/Sorting/Hotel Booking/problem.md: -------------------------------------------------------------------------------- 1 | ### Problem Link: 2 | 3 | https://www.interviewbit.com/problems/hotel-bookings-possible/ 4 | -------------------------------------------------------------------------------- /InterviewBit_problems/Sorting/Max NonNegative SubArray/problem.md: -------------------------------------------------------------------------------- 1 | ### Problem Link: 2 | 3 | https://www.interviewbit.com/problems/max-non-negative-subarray/ -------------------------------------------------------------------------------- /InterviewBit_problems/Sorting/Max Sum Contiguous SubArray/problem.md: -------------------------------------------------------------------------------- 1 | ### Problem Link: 2 | 3 | https://www.interviewbit.com/problems/max-sum-contiguous-subarray/ 4 | -------------------------------------------------------------------------------- /InterviewBit_problems/Sorting/Max Unsorted SubArray/problem.md: -------------------------------------------------------------------------------- 1 | ### Problem Link: 2 | 3 | https://www.interviewbit.com/problems/maximum-unsorted-subarray/ 4 | -------------------------------------------------------------------------------- /InterviewBit_problems/Stack and Queues/Largest Rectangle in Histogram/problem.md: -------------------------------------------------------------------------------- 1 | # Problem link 2 | 3 | > https://www.interviewbit.com/problems/largest-rectangle-in-histogram/ -------------------------------------------------------------------------------- /InterviewBit_problems/Symmetric_Traversal/Problem.md: -------------------------------------------------------------------------------- 1 | //Problem link : 2 | 3 | https://www.interviewbit.com/problems/inorder-traversal/ 4 | 5 | -------------------------------------------------------------------------------- /InterviewBit_problems/TwoPointers/Merger2SortedList/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link 2 | 3 | https://www.interviewbit.com/problems/merge-two-sorted-lists-ii/ 4 | -------------------------------------------------------------------------------- /InterviewBit_problems/TwoPointers/remove_duplicate_elements/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link 2 | 3 | https://www.interviewbit.com/problems/remove-duplicates-from-sorted-array/ -------------------------------------------------------------------------------- /InterviewBit_problems/TwoPointers/remove_duplicate_elements_II/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link 2 | https://www.interviewbit.com/problems/remove-duplicates-from-sorted-array-ii/ 3 | -------------------------------------------------------------------------------- /InterviewBit_problems/TwoPointers/remove_givenElement_from_array/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link 2 | 3 | https://www.interviewbit.com/problems/remove-element-from-array/ -------------------------------------------------------------------------------- /LeetCode_problems/Add Strings/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://leetcode.com/problems/add-strings/ -------------------------------------------------------------------------------- /LeetCode_problems/Add Strings/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string addStrings(string num1, string num2) { 4 | return to_string(std::stoi(num1)+std::stoi(num2)); 5 | // std::stoi is used to convert string to int (default is decimal, but the base can also be defined as a second parameter) 6 | // to_string converts int to string 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /LeetCode_problems/Add Two Numbers Linked List/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. 4 | 5 | You may assume the two numbers do not contain any leading zero, except the number 0 itself. 6 | 7 | Example:
8 | Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
9 | Output: 7 -> 0 -> 8
10 | Explanation: 342 + 465 = 807. 11 | 12 | ## Link 13 | https://leetcode.com/problems/add-two-numbers/ -------------------------------------------------------------------------------- /LeetCode_problems/Anagrams/problem.md: -------------------------------------------------------------------------------- 1 | ## Problem Link 2 | https://leetcode.com/problems/group-anagrams/ -------------------------------------------------------------------------------- /LeetCode_problems/Array Partition 1/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://leetcode.com/problems/array-partition-i/ -------------------------------------------------------------------------------- /LeetCode_problems/Array Partition 1/solution(1).py: -------------------------------------------------------------------------------- 1 | #we first sort the array, then we traverse the array by a step of 2 hence we get the required sum. we need the minimum value of a pair 2 | #so if the array is [2,1,3,4] it sorts to [1,2,3,4] then it takes the sum of 1 and 3 which is required. 3 | class Solution: 4 | def arrayPairSum(self, nums: List[int]) -> int: 5 | nums=sorted(nums) 6 | s=0 7 | for i in range(0,len(nums),2): 8 | s=s+nums[i] 9 | return s 10 | -------------------------------------------------------------------------------- /LeetCode_problems/Binary_Tree_level_Order_Traversal/problem.md: -------------------------------------------------------------------------------- 1 | Binary Tree Level Order Traversal 2 | 3 | Link to the problem: 4 | 5 | https://leetcode.com/problems/binary-tree-level-order-traversal/ 6 | -------------------------------------------------------------------------------- /LeetCode_problems/Combination Sum/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://leetcode.com/problems/combination-sum/ -------------------------------------------------------------------------------- /LeetCode_problems/Compare Version Number/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://leetcode.com/problems/compare-version-numbers/ 4 | -------------------------------------------------------------------------------- /LeetCode_problems/Container With Most Water/problem.md: -------------------------------------------------------------------------------- 1 | link : https://leetcode.com/problems/container-with-most-water/ 2 | Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). Find two lines, which, together with the x-axis forms a container, such that the container contains the most water. 3 | 4 | Notice that you may not slant the container. 5 | -------------------------------------------------------------------------------- /LeetCode_problems/Convert Roman number to Integer/problem.md: -------------------------------------------------------------------------------- 1 | linnk: https://leetcode.com/problems/roman-to-integer/ -------------------------------------------------------------------------------- /LeetCode_problems/Count All Valid Pickup and Delivery Options/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://leetcode.com/problems/count-all-valid-pickup-and-delivery-options/ 4 | -------------------------------------------------------------------------------- /LeetCode_problems/Count and Say/question.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | ## Count And Say 3 | The count-and-say sequence is the sequence of integers beginning as follows: 4 | 5 | 1, 11, 21, 1211, 111221, ... 6 | 1 is read off as one 1 or 11. 11 is read off as two 1s or 21. 7 | 8 | 21 is read off as one 2, then one 1 or 1211. 9 | 10 | Given an integer n, generate the nth sequence. 11 | 12 | Note: The sequence of integers will be represented as a string. 13 | 14 | Example: 15 | 16 | if n = 2, the sequence is 11. 17 | 18 | Link: https://leetcode.com/problems/count-and-say/ 19 | -------------------------------------------------------------------------------- /LeetCode_problems/Cycle Detection in Linked List/problem.md: -------------------------------------------------------------------------------- 1 | This problem is present on leetcode witha name of linkedlist cylce 2 | https://leetcode.com/problems/linked-list-cycle/ 3 | -------------------------------------------------------------------------------- /LeetCode_problems/DecryptStringFromAlphabetToInteger/problem.md: -------------------------------------------------------------------------------- 1 | Problem link 2 | 3 | https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/ 4 | -------------------------------------------------------------------------------- /LeetCode_problems/Defanging an IP Address/problem.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/defanging-an-ip-address/ 2 | -------------------------------------------------------------------------------- /LeetCode_problems/Defanging an IP Address/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def defangIPaddr(self, address: str) -> str: 3 | # replace all occurrences of "." with "[.]" 4 | return address.replace('.', '[.]') 5 | -------------------------------------------------------------------------------- /LeetCode_problems/Delete Node/Problem.md: -------------------------------------------------------------------------------- 1 | #Problem 2 | Link: https://leetcode.com/problems/delete-node-in-a-linked-list/ 3 | Difficulty:Easy -------------------------------------------------------------------------------- /LeetCode_problems/Distinct Subsequence II/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://leetcode.com/problems/distinct-subsequences-ii/ -------------------------------------------------------------------------------- /LeetCode_problems/Dungeon Game/problem.md: -------------------------------------------------------------------------------- 1 | Link to problem : 2 | https://leetcode.com/problems/dungeon-game/ -------------------------------------------------------------------------------- /LeetCode_problems/Find all duplicates in an array/problem.md: -------------------------------------------------------------------------------- 1 | Leetcode Find all duplicates in an array(Medium) 2 | https://leetcode.com/problems/find-all-duplicates-in-an-array/ -------------------------------------------------------------------------------- /LeetCode_problems/Find_the_Difference/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://leetcode.com/problems/find-the-difference/ -------------------------------------------------------------------------------- /LeetCode_problems/Find_the_Difference/solution.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | class Solution: 3 | def findTheDifference(self, s: str, t: str) -> str: 4 | cts=Counter(s) 5 | ctt=Counter(t) 6 | for i in ctt.keys(): 7 | if ctt[i]>cts[i]: 8 | return i 9 | return "" 10 | # make a frequency map of both the strings 11 | # iterate over keys of string t 12 | # check if value of that key is bigger than the value of 13 | #key in freq map of s, then that is the extra letter 14 | # return empty string if both string equal -------------------------------------------------------------------------------- /LeetCode_problems/First Missing Positive/problem.md: -------------------------------------------------------------------------------- 1 | Problem link: https://leetcode.com/problems/first-missing-positive/ -------------------------------------------------------------------------------- /LeetCode_problems/First_Unique_Character_in_a_String/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://leetcode.com/problems/first-unique-character-in-a-string/ -------------------------------------------------------------------------------- /LeetCode_problems/First_Unique_Character_in_a_String/solution.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | class Solution: 3 | def firstUniqChar(self, s: str) -> int: 4 | ct=Counter(s) 5 | for i in range(len(s)): 6 | if ct[s[i]]==1: 7 | return i 8 | return -1 9 | # Counter makes a frequency map of letters in string 10 | # we iterate over the letters of the string and check if it has only 1 count, then return the first one 11 | # else if no count is 1, we return -1 because no letter is unique 12 | 13 | -------------------------------------------------------------------------------- /LeetCode_problems/Gas Station/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://leetcode.com/problems/gas-station/ -------------------------------------------------------------------------------- /LeetCode_problems/H_Index/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://leetcode.com/problems/h-index/ 2 | -------------------------------------------------------------------------------- /LeetCode_problems/Insert Interval/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://leetcode.com/problems/insert-interval/ -------------------------------------------------------------------------------- /LeetCode_problems/Invert Binary Tree/problem.md: -------------------------------------------------------------------------------- 1 | Here is the Problem Statement : 2 | https://leetcode.com/problems/invert-binary-tree/ 3 | -------------------------------------------------------------------------------- /LeetCode_problems/Jewels and Stones/problem.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/jewels-and-stones/ 2 | -------------------------------------------------------------------------------- /LeetCode_problems/Jewels and Stones/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numJewelsInStones(string J, string S) { 4 | int count = 0; // taking the count of stones that are jewels 5 | for(int i=0;i int: 3 | # maintain count of jewels 4 | jewels = 0 5 | 6 | # check how many jewels are in the string of stones 7 | for j in J: 8 | jewels += S.count(j) 9 | 10 | return jewels 11 | -------------------------------------------------------------------------------- /LeetCode_problems/K Closest Points to Origin/Problem.md: -------------------------------------------------------------------------------- 1 | Link : https://leetcode.com/problems/k-closest-points-to-origin/ 2 | 3 | We have a list of points on the plane. Find the K closest points to the origin (0, 0). 4 | 5 | (Here, the distance between two points on a plane is the Euclidean distance.) 6 | 7 | You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in.) -------------------------------------------------------------------------------- /LeetCode_problems/K Closest Points to Origin/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[][] kClosest(int[][] points, int K) { 3 | PriorityQueue maxHeap = new PriorityQueue<>((a, b) -> (b[0] * b[0] + b[1] * b[1]) - (a[0] * a[0] + a[1] * a[1])); 4 | //create a priority queue ( for max heap) 5 | for (int[] p : points) { 6 | maxHeap.offer(p); // add it in heap 7 | if (maxHeap.size() > K) { 8 | maxHeap.poll(); 9 | } 10 | } 11 | int[][] ans = new int[maxHeap.size()][2]; // storage for calculating answers 12 | int i = 0; 13 | while (!maxHeap.isEmpty()) { 14 | ans[i++] = maxHeap.poll();// increment i and key in the value in ans array which represents the k closest points 15 | } 16 | return ans; 17 | } 18 | } -------------------------------------------------------------------------------- /LeetCode_problems/Least Number of Unique Integers after K Removals/problem.md: -------------------------------------------------------------------------------- 1 | 2 | https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals/ 3 | 4 | Given an array of integers arr and an integer k. 5 | Find the least number of unique integers after removing exactly k elements. 6 | 7 | Input: arr = [4,3,1,1,3,3,2], k = 3 8 | Output: 2 9 | Explanation: Remove 4, 2 and either one of the two 1s or three 3s. 1 and 3 will be left. 10 | -------------------------------------------------------------------------------- /LeetCode_problems/Length of Last Word/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://leetcode.com/problems/length-of-last-word/ 4 | -------------------------------------------------------------------------------- /LeetCode_problems/Linked List Components/problem.md: -------------------------------------------------------------------------------- 1 | # 817.Linked List Components 2 | 3 | [LINK TO THE PROBLEM](https://leetcode.com/problems/linked-list-components/) -------------------------------------------------------------------------------- /LeetCode_problems/Longest Substring Without Repeating Characters/Problem.md: -------------------------------------------------------------------------------- 1 | # 3. Longest Substring Without Repeating Characters 2 | 3 | [LINK TO THE PROBLEM](https://leetcode.com/problems/longest-substring-without-repeating-characters/) -------------------------------------------------------------------------------- /LeetCode_problems/Majority Element/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://leetcode.com/problems/majority-element/ -------------------------------------------------------------------------------- /LeetCode_problems/Majority Element/solution1.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def majorityElement(self, nums: List[int]) -> int: 3 | #we make a set of the given list 4 | s=list(set(nums)) 5 | #iterate over the set 6 | for i in range(len(s)): 7 | #we check if the count of the element is >n/2 by using the count function as soon as we get that required element which satisfies the condition we break out the loop and return the value to the main function. 8 | if nums.count(s[i])>len(nums)/2: 9 | break 10 | return s[i] -------------------------------------------------------------------------------- /LeetCode_problems/Max level Sum Of Binary Tree/Max_Level.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree/ -------------------------------------------------------------------------------- /LeetCode_problems/Maximum Product Subarray/problem.md: -------------------------------------------------------------------------------- 1 | Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product. 2 | 3 | Example 1: 4 | 5 | Input: [2,3,-2,4] 6 | Output: 6 7 | Explanation: [2,3] has the largest product 6. 8 | Example 2: 9 | 10 | Input: [-2,0,-1] 11 | Output: 0 12 | Explanation: The result cannot be 2, because [-2,-1] is not a subarray. 13 | 14 | Link:- https://leetcode.com/problems/maximum-product-subarray/ -------------------------------------------------------------------------------- /LeetCode_problems/Maximum Sum Circular Subarray/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://leetcode.com/problems/maximum-sum-circular-subarray/ -------------------------------------------------------------------------------- /LeetCode_problems/Minimum Path Sum/problem.md: -------------------------------------------------------------------------------- 1 | ## Problem Link 2 | https://leetcode.com/problems/minimum-path-sum/ -------------------------------------------------------------------------------- /LeetCode_problems/Minimum Size Subarray/problem.md: -------------------------------------------------------------------------------- 1 | Link to problem: https://leetcode.com/problems/minimum-size-subarray-sum/ 2 | -------------------------------------------------------------------------------- /LeetCode_problems/Monotonic Array/problem.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://leetcode.com/problems/monotonic-array/ -------------------------------------------------------------------------------- /LeetCode_problems/Monotonic Array/solution_1.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isMonotonic(self, A: List[int]) -> bool: 3 | #an array is monotonic if it is either increasing or decreasing, so we check if the array is equal to 4 | #its sorted version in either descending order or ascending order. If yes return True 5 | #else return False. 6 | if A==sorted(A): 7 | return True 8 | if A==sorted(A,reverse=True): 9 | return True 10 | return False -------------------------------------------------------------------------------- /LeetCode_problems/Next Permutation/problem.md: -------------------------------------------------------------------------------- 1 | [link to the problem](https://leetcode.com/problems/next-permutation/) 2 | -------------------------------------------------------------------------------- /LeetCode_problems/Number of Islands/problem.md: -------------------------------------------------------------------------------- 1 | Link to problem: https://leetcode.com/problems/number-of-islands/ 2 | -------------------------------------------------------------------------------- /LeetCode_problems/Number_of_good_pairs/problem.md: -------------------------------------------------------------------------------- 1 | Leetcode Number of Good Pairs(Easy) 2 | https://leetcode.com/problems/number-of-good-pairs/ -------------------------------------------------------------------------------- /LeetCode_problems/Permutation Palindrome/Problem Statement.md: -------------------------------------------------------------------------------- 1 | ## Problem Statement 2 | 3 | Palindrome Permutation: Given a string, write a function to check if it is a permutation of a palindrome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. The palindrome does not need to be limited to just dictionary words. 4 | 5 | ### EXAMPLE 6 | Input: Tact Coa 7 | Output: True (permutations: "taco cat", "atco eta", etc.) 8 | 9 | 10 | -------------------------------------------------------------------------------- /LeetCode_problems/Permutation Sequence/Problem.md: -------------------------------------------------------------------------------- 1 | # LINK: 2 | https://leetcode.com/problems/permutation-sequence/ 3 | -------------------------------------------------------------------------------- /LeetCode_problems/Plus One/problem.md: -------------------------------------------------------------------------------- 1 | Leetcode Plus one(Easy) 2 | https://leetcode.com/problems/plus-one/ -------------------------------------------------------------------------------- /LeetCode_problems/Possible Bipartition/Problem.md: -------------------------------------------------------------------------------- 1 | Link: https://leetcode.com/problems/possible-bipartition/ 2 | 3 | Given a set of N people (numbered 1, 2, ..., N), we would like to split everyone into two groups of any size. 4 | 5 | Each person may dislike some other people, and they should not go into the same group. 6 | 7 | Formally, if dislikes[i] = [a, b], it means it is not allowed to put the people numbered a and b into the same group. 8 | 9 | Return true if and only if it is possible to split everyone into two groups in this way. -------------------------------------------------------------------------------- /LeetCode_problems/Queue Reconstruction by Height/Question.txt: -------------------------------------------------------------------------------- 1 | Question type- Greedy 2 | https://leetcode.com/problems/queue-reconstruction-by-height/ -------------------------------------------------------------------------------- /LeetCode_problems/Range addition II/problem.md: -------------------------------------------------------------------------------- 1 |

Range Addition II

2 | Link : https://leetcode.com/problems/range-addition-ii/ 3 | -------------------------------------------------------------------------------- /LeetCode_problems/Remove Covered Intervals/problem.md: -------------------------------------------------------------------------------- 1 | ## Problem Link 2 | https://leetcode.com/problems/remove-covered-intervals/ -------------------------------------------------------------------------------- /LeetCode_problems/Remove Duplicates from Sorted List/Problem.md: -------------------------------------------------------------------------------- 1 | ## Link for the Leetcode Problem 2 | 3 | [LeetCode](https://leetcode.com/problems/remove-duplicates-from-sorted-list/) 4 | -------------------------------------------------------------------------------- /LeetCode_problems/Remove Duplicates from Sorted List/Solution: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def deleteDuplicates(self, head: ListNode) -> ListNode: 3 | if head==None: 4 | return head 5 | # We track the prev and current nodes 6 | current= head.next 7 | prev=head 8 | while current!=None: 9 | # If the vals of the two nodes are the same advance current 10 | if current.val==prev.val: 11 | prev.next=current.next 12 | current=current.next 13 | else: 14 | # Otherwise we know they are different vals 15 | current=current.next 16 | prev=prev.next 17 | return head 18 | -------------------------------------------------------------------------------- /LeetCode_problems/Remove Element/problem.md: -------------------------------------------------------------------------------- 1 | # 27.Remove Element 2 | 3 | [LINK TO THE PROBLEM](https://leetcode.com/problems/remove-element/) -------------------------------------------------------------------------------- /LeetCode_problems/Remove Element/solution.cpp: -------------------------------------------------------------------------------- 1 | 2 | //Remove Element 3 | //here we are given an array containing some elements along with the value to be removed from the array 4 | //then return the count of remaining elements 5 | 6 | class Solution { 7 | public: 8 | int removeElement(vector& nums, int val) { 9 | int c=0;//initialize the count to be 0 10 | for (auto i = nums.begin(); i != nums.end(); ++i) { //traversing the nums vector 11 | if (*i == val) { 12 | nums.erase(i); //if the iterator points to the value to be removed then we delete it 13 | i--; //decrement the iterator by 1 14 | } 15 | else c++;//increment the count by 1 16 | } 17 | return c; //here we return the count of remaining elements 18 | } 19 | }; -------------------------------------------------------------------------------- /LeetCode_problems/Remove Nth Node from End/problem.md: -------------------------------------------------------------------------------- 1 | # Remove Nth Node from End of List 2 | 3 | [LINK TO THE PROBLEM](https://leetcode.com/problems/remove-nth-node-from-end-of-list/) -------------------------------------------------------------------------------- /LeetCode_problems/Reorder_List/problem.md: -------------------------------------------------------------------------------- 1 | # 143.Reorder List 2 | 3 | [LINK TO THE PROBLEM](https://leetcode.com/problems/reorder-list/) -------------------------------------------------------------------------------- /LeetCode_problems/Reverse Integer/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://leetcode.com/problems/reverse-integer/ -------------------------------------------------------------------------------- /LeetCode_problems/Roman to Integer/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://leetcode.com/problems/roman-to-integer/ -------------------------------------------------------------------------------- /LeetCode_problems/Rotate Digits/problem.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/rotated-digits/ 2 | -------------------------------------------------------------------------------- /LeetCode_problems/Rotate Digits/solution.js: -------------------------------------------------------------------------------- 1 | var IsGood = function (n) { 2 | let result = false; 3 | while (n > 0) { 4 | // Checking the last digit of the number by mod 10 5 | let digit = n % 10; 6 | // ignore 0, 1, 8; by themselves, no change 7 | if (digit === 3 || digit === 4 || digit === 7) return false; 8 | if (digit === 2 || digit === 5 || digit === 6 || digit === 9) result = true; 9 | // excluding the last digit 10 | n /= 10; 11 | } 12 | return result; 13 | }; 14 | 15 | var rotatedDigits = function (N) { 16 | let count = 0; 17 | for (let i = 1; i <= N; i++) { 18 | if (IsGood(i)) count++; 19 | } 20 | return count; 21 | }; 22 | -------------------------------------------------------------------------------- /LeetCode_problems/Rotate Image/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://leetcode.com/problems/rotate-image/ 4 | -------------------------------------------------------------------------------- /LeetCode_problems/Running Sum of 1d Array/problem.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/running-sum-of-1d-array/ 2 | -------------------------------------------------------------------------------- /LeetCode_problems/Running Sum of 1d Array/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def runningSum(self, nums: List[int]) -> List[int]: 3 | # declare array to return 4 | output = list() 5 | 6 | # compute running sum for each index 7 | for i in range(len(nums)): 8 | output.append(sum(nums[:i+1])) 9 | 10 | return output 11 | -------------------------------------------------------------------------------- /LeetCode_problems/Same Tree/problem.md: -------------------------------------------------------------------------------- 1 | Leetcode Same Tree(Easy) 2 | https://leetcode.com/problems/same-tree/ -------------------------------------------------------------------------------- /LeetCode_problems/Search Rotated Sorted Array/problem.md: -------------------------------------------------------------------------------- 1 | ## Problem Link 2 | https://leetcode.com/problems/search-in-rotated-sorted-array/ -------------------------------------------------------------------------------- /LeetCode_problems/Single Number/problem.md: -------------------------------------------------------------------------------- 1 | problem link: https://leetcode.com/problems/single-number/ 2 | -------------------------------------------------------------------------------- /LeetCode_problems/Single Number/solution.cpp: -------------------------------------------------------------------------------- 1 | /*we know, if a = b then a xor b = 0 2 | here all numbers are occurring twice except one, so if we xor all numbers we will get that single number 3 | For example a[3] = {1,1,2}, then 1^1^2 = 2, which is our ans*/ 4 | 5 | class Solution { 6 | public: 7 | int singleNumber(vector& nums) { 8 | int ans=0; 9 | for(int i=0;imx or n cur: 17 | cur = arr[i] 18 | no_of_win = 0 19 | no_of_win += 1 '''if smaller simply increment the number of wins''' 20 | if (no_of_win == k): break 21 | return cur -------------------------------------------------------------------------------- /LeetCode_problems/Winner of an Array Game/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://leetcode.com/problems/find-the-winner-of-an-array-game/ -------------------------------------------------------------------------------- /LeetCode_problems/Wriggle_Sort_2/problem.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/wiggle-sort-ii/ -------------------------------------------------------------------------------- /LeetCode_problems/XOR Operation in an Array/problem.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/xor-operation-in-an-array/ 2 | -------------------------------------------------------------------------------- /LeetCode_problems/XOR Operation in an Array/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def xorOperation(self, n: int, start: int) -> int: 3 | # build the initial array of numbers following the formula 4 | nums = list() 5 | for i in range(n): 6 | nums.append(2 * i + start) 7 | 8 | # compute the xor of all of the numbers 9 | xor = nums[0] 10 | for num in nums[1:]: 11 | xor ^= num 12 | return xor 13 | -------------------------------------------------------------------------------- /LeetCode_problems/add digits/problem.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/add-digits/ -------------------------------------------------------------------------------- /LeetCode_problems/add digits/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int addDigits(int num) { 4 | //If number is 0 return 0 5 | if(num==0) 6 | { 7 | return 0; 8 | } 9 | //if the number is single digit return the number itself 10 | if(num>0&&num<=9) 11 | { 12 | return num; 13 | } 14 | //if number is divisible by 9 then by the divisibility test that a number divided by 9 has 15 | //the sum of digits as 9 return 9 16 | 17 | if(num%9==0) 18 | { 19 | return 9; 20 | } 21 | //else return the remainder on dividing by 9. 22 | return num%9; 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /LeetCode_problems/add one row to tree/problem.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/add-one-row-to-tree/ -------------------------------------------------------------------------------- /LeetCode_problems/add-binary/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://leetcode.com/problems/add-binary/ -------------------------------------------------------------------------------- /LeetCode_problems/all elements in two binary search trees/problem.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/all-elements-in-two-binary-search-trees/ -------------------------------------------------------------------------------- /LeetCode_problems/count-good-triplets/Solution.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Mon Oct 5 2020 4 | 5 | @author: Shrey1608 6 | """ 7 | # Approach : 1) using 3 loops for checking the condition(Time complexity O(n^3)| space complexity O(1)) 8 | 9 | 10 | 11 | # Solution:(Approach 1) 12 | class Solution: 13 | def countGoodTriplets(self, arr: List[int], a: int, b: int, c: int) -> int: 14 | n=len(arr) 15 | count=0 16 | for i in range(n-2): 17 | for j in range(i+1,n-1): 18 | if (abs(arr[i] - arr[j]) > a): 19 | continue 20 | for k in range(j+1,n): 21 | if (abs(arr[j] - arr[k]) <= b and abs(arr[i] - arr[k]) <= c): 22 | count+=1 23 | return count -------------------------------------------------------------------------------- /LeetCode_problems/count-good-triplets/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://leetcode.com/problems/count-good-triplets/ -------------------------------------------------------------------------------- /LeetCode_problems/first-bad-version/Solution.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Mon Oct 5 2020 4 | 5 | @author: Shrey1608 6 | """ 7 | # Approach : 1)It is not difficult to see that this could be solved using a classic algorithm - Binary search.(time complexity : 0(logn) || space complexity: O(1)) 8 | 9 | 10 | # Solution:(Approach 1) 11 | class Solution: 12 | def firstBadVersion(self, n): 13 | """ 14 | :type n: int 15 | :rtype: int 16 | """ 17 | left,right=0,n 18 | while left < right: 19 | mid = left + (right - left) // 2 20 | if isBadVersion(mid): 21 | right = mid 22 | else: 23 | left = mid + 1 24 | return left -------------------------------------------------------------------------------- /LeetCode_problems/first-bad-version/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://leetcode.com/problems/first-bad-version/ -------------------------------------------------------------------------------- /LeetCode_problems/graph clone/problem.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/clone-graph/ -------------------------------------------------------------------------------- /LeetCode_problems/graph clone/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | unordered_map m; //a map to store the cloned information about a node. 3 | public: 4 | 5 | Node* cloneGraph(Node* node) { 6 | if(node==NULL) 7 | return node; 8 | 9 | if(m.find(node->val) != m.end()) //if the node has already been cloned, return the same. 10 | return m[node->val]; 11 | 12 | Node* temp=new Node(node->val); //create a new node for the node. 13 | m[node->val]=temp; //store it in the map. 14 | for (auto neighbor : node->neighbors) 15 | temp->neighbors.push_back(cloneGraph(neighbor)); //clone the neighbors 16 | 17 | return temp; //return the cloned new node. 18 | } 19 | }; -------------------------------------------------------------------------------- /LeetCode_problems/insert-into-a-binary-search-tree/Add Strings/Solution.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Mon Oct 5 2020 4 | 5 | @author: Shrey1608 6 | """ 7 | 8 | # Approach : 1) we will use recursion technique to insert the element into a bst(Time complexity= O(H)(h is height of the tree) 9 | 10 | 11 | 12 | #Solution : Recursion 13 | 14 | class Solution: 15 | def insertIntoBST(self, root: TreeNode, val: int) -> TreeNode: 16 | if not root: 17 | return TreeNode(val) 18 | if root.val> val: 19 | root.left=self.insertIntoBST(root.left,val) 20 | else: 21 | root.right=self.insertIntoBST(root.right,val) 22 | return root -------------------------------------------------------------------------------- /LeetCode_problems/insert-into-a-binary-search-tree/Add Strings/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://leetcode.com/problems/insert-into-a-binary-search-tree/ -------------------------------------------------------------------------------- /LeetCode_problems/kth-smallest-element-in-a-bst/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://leetcode.com/problems/kth-smallest-element-in-a-bst/ -------------------------------------------------------------------------------- /LeetCode_problems/kth_factor_of_n/Problem.md: -------------------------------------------------------------------------------- 1 | LINK https://leetcode.com/problems/the-kth-factor-of-n/ -------------------------------------------------------------------------------- /LeetCode_problems/kth_factor_of_n/solution.py: -------------------------------------------------------------------------------- 1 | # This the main class for the solution 2 | class Solution: # This class takes two integer n and k as input 3 | def kthFactor(self, n: int, k: int) -> int: # Here n is the number and k is the kth factor. 4 | ls = [] # Initialize the empty list 5 | i = 1 6 | while(i<=n): # In this while loop we append all the factors of the number n 7 | if n%i == 0: 8 | ls.append(i) # Appending the number to the list. 9 | i += 1 10 | try: # Returns the Kth factor if exist 11 | return ls[k-1] 12 | except: # else returns -1 13 | return -1 -------------------------------------------------------------------------------- /LeetCode_problems/merge k sorted list/problem.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/merge-k-sorted-lists/ 2 | -------------------------------------------------------------------------------- /LeetCode_problems/merge two linked list/problem.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/merge-two-sorted-lists/ 2 | -------------------------------------------------------------------------------- /LeetCode_problems/range-sum-of-bst/problem.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link: https://leetcode.com/problems/range-sum-of-bst/ -------------------------------------------------------------------------------- /LeetCode_problems/subsets/problem.md: -------------------------------------------------------------------------------- 1 | [link to the problem](https://leetcode.com/problems/subsets/) 2 | -------------------------------------------------------------------------------- /Misc/Caesar_Cipher_Encryptor/problem.md: -------------------------------------------------------------------------------- 1 | # Caesar Cipher Encryptor 2 | ## Problem 3 | Given a non-empty string of lowercase letters and a non-negative integer representing a key, write a function that returns a new string obtained by shifting every letter in the input string by k positions in the alphabet, where k is the key. 4 | 5 | Note that letters should "wrap" around the alphabet; in other words, the letter 'z' shifted by one returns the letter 'a'. 6 | 7 | ## Input 8 | A string consisting of the message in lowercase letters. 9 | A key by which the letter have to be shifted 10 | 11 | ## Output 12 | A string consisting of encrypted message. 13 | 14 | ## Example 15 | - ```caesarCipherEncryptor("xyz", 2)```, returns "zab" 16 | - ```caesarCipherEncryptor("cat", 5)```, returns "hfy" -------------------------------------------------------------------------------- /Misc/Deja_vu/Instructions.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vishruth-S/CompetitiveCode/28a3ea13d744b799b628ee71ef6db82e8d9e3fd3/Misc/Deja_vu/Instructions.jpg -------------------------------------------------------------------------------- /Misc/Deja_vu/readme.md: -------------------------------------------------------------------------------- 1 | # Deja Vu 2 | Given a string of random letters, your task is to evaluate whether any string is repeated in the string or if you hit only unique keys when typing. 3 | 4 | ## Input format 5 | A string of random characters 6 | 7 | ## Output format 8 | A string that says "Deja Vu" if any character is repeated in the input string, or 9 | A string that says "Unique" if no characters are repeated. 10 | 11 | ## Test Cases 12 | ### Sample 1 13 | **input**: "aaafhgi" 14 | **output**: "DeJa vu" 15 | 16 | ### Sample 2 17 | **input**: "cakemog" 18 | **output**: "Unique" 19 | 20 | ### Sample 3 21 | **input**: "caakemog" 22 | **output**: "Deja Vu" 23 | -------------------------------------------------------------------------------- /Misc/Deja_vu/solution1.py: -------------------------------------------------------------------------------- 1 | """ 2 | solution 1 3 | author: fr4nkl1n-1k3h 4 | de ja vu 5 | """ 6 | 7 | def dejavu(string): 8 | if len(string) == len(set(string)): #set() removes duplicates from a string. So if set(string) is same as actual string, then it is unique 9 | return "Unique" 10 | elif len(string) > len(set(string)): #Else, it contains duplicates and hence not unique 11 | return "DeJa Vu" 12 | 13 | str = input() # getting input 14 | print(dejavu(str)) 15 | 16 | # Test Case 1 17 | # print(dejavu("aaafhgi")) 18 | 19 | # Test Case 2 20 | # print(dejavu("cakemog")) 21 | 22 | # Test Case 3 23 | # print(dejavu("caakemog")) 24 | -------------------------------------------------------------------------------- /Misc/Dynamic_Programming_Knapsack_Problem/Problem.md: -------------------------------------------------------------------------------- 1 | 0-1 Knapsack Problem: 2 | 3 | 4 | Given weights and values of n items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack. In other words, given two integer arrays val[0..n-1] and wt[0..n-1] which represent values and weights associated with n items respectively. Also given an integer W which represents knapsack capacity, find out the maximum value subset of val[] such that sum of the weights of this subset is smaller than or equal to W. You cannot break an item, either pick the complete item or don’t pick it (0-1 property). 5 | -------------------------------------------------------------------------------- /Misc/Fibonacci_Search/Problem.md: -------------------------------------------------------------------------------- 1 | Fibonacci Search 2 | 3 | Given a sorted array arr[] of size n and an element x to be searched in it. Return index of x if it is present in array else return -1. 4 | Examples: 5 | 6 | Input: arr[] = {2, 3, 4, 10, 40}, x = 10 7 | Output: 3 8 | Element x is present at index 3. 9 | 10 | Input: arr[] = {2, 3, 4, 10, 40}, x = 11 11 | Output: -1 12 | Element x is not present. 13 | Fibonacci Search is a comparison-based technique that uses Fibonacci numbers to search an element in a sorted array. 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Misc/Math and Strings Problems/Anagram Problem/problem statement.txt: -------------------------------------------------------------------------------- 1 | Q. Taking input of two lines or Strings from the user, compare and find if they are anagrams of each other or not. 2 | 3 | What are anagrams? Two statements with the same alphabets used the same no. of times but irrespective of spacing in words. 4 | 5 | Ex. INPUT1: I LOVE COMPUTERS INPUT2: MOLE COVERS IT UP OUTPUT: YES LOGIC: they're just rearrangement of the used alphabets. hence they are anagrams. 6 | 7 | -------------------------------------------------------------------------------- /Misc/Math and Strings Problems/Armstrong Number Problem/Problem Statement.txt: -------------------------------------------------------------------------------- 1 | Q. Check if the given three digit no. is an armstrong number or not. 2 | 3 | What is an armstrong number? 4 | A number which is equal to the sum of the cubes of it's digits. 5 | 6 | 7 | Ex. 8 | 9 | INPUT: 153 10 | OUTPUT: It is an armstrong number 11 | LOGIC: 153=1x1x1+5x5x5+3x3x3 12 | -------------------------------------------------------------------------------- /Misc/Math and Strings Problems/Spy Number Problem/problem statement.txt: -------------------------------------------------------------------------------- 1 | Q. Check if the given no. is a spy no. or not. 2 | 3 | What is a spy number? 4 | A number whose sum and product of digits is the same. 5 | 6 | 7 | Ex. 8 | INPUT: 123 9 | OUTPUT: YES 10 | LOGIC: 1+2+3=1x2x3 11 | -------------------------------------------------------------------------------- /Misc/Math and Strings Problems/The One with the Fibonacci/problem statement.txt: -------------------------------------------------------------------------------- 1 | Q. check if the given no. is part of the fibonacci series. 2 | If so, print the continuation of fibonacci upto next 5 terms. 3 | 4 | 5 | What is a fibonacci series? 6 | A serie with first term 1 and second term 2 which proceeds in the fashion that 7 | the next term is the sum of previous two terms. 8 | 9 | 10 | Ex. 11 | INPUT: 5 12 | OUTPUT: 5 8 13 21 44 65 13 | LOGIC: 1,2,3,5,8.... is the fibonacci and 5 is a member 14 | 5+3=8, 8+5=13... so on 15 | -------------------------------------------------------------------------------- /Misc/Monotonic_Array/problem.md: -------------------------------------------------------------------------------- 1 | # Montonic Array 2 | Write a function that takes in an array of integers and returns a boolean representing whether the array is monotonic. 3 | 4 | An array is said to be monotonic if its elements, from left to right, are entirely non-increasing or entirely non-decreasing. 5 | 6 | ## Example 7 | Input: [-1, -5, -10, -1100, -1100, -1101, -1102, -9001] 8 | Output: True 9 | **Explanation** 10 | The given input is monotonic because every subsequent number is 11 | either equal to or less than the previous number. 12 | 13 | ## Example 2 14 | Input: [1, 1, 2, 3, 4, 5, 5, 5, 6, 7, 8, 7, 9, 10, 11] 15 | Output: False 16 | **Explanation** 17 | The given input is not monotonic because after the number 8, number 7 is present which changes the flow of purely increasing to non-monotonic 18 | -------------------------------------------------------------------------------- /Misc/SumOfAllDigits/solution1.py: -------------------------------------------------------------------------------- 1 | a, b = map(int, input().split()) 2 | 3 | # Find sum of digits of a number 4 | def sumDigits(n): 5 | tot = 0 6 | while(n > 0): 7 | tot += n % 10 8 | n //= 10 9 | return tot 10 | 11 | # Recursively find sum of digits till the number is single digit 12 | def sumOfDigits(n): 13 | k = sumDigits(n) 14 | if k > 9: 15 | return sumOfDigits(k) 16 | else: 17 | return k 18 | 19 | 20 | num = sumDigits(a) * b 21 | print(sumOfDigits(num)) 22 | -------------------------------------------------------------------------------- /Spoj_problems/ACPC10A/problem.md: -------------------------------------------------------------------------------- 1 |

Problem Link

2 | Problem Link = https://www.spoj.com/problems/ACPC10A/ 3 |
4 | Problem Tag = #AP #GP 5 | -------------------------------------------------------------------------------- /Spoj_problems/ACPC10A/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define jaadu ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 4 | typedef long long int uli; 5 | /* 6 | In this problem, we need to find the next sequence of give AP or GP series. 7 | If a2-a1 == a3-a2, then its a AP series, otherwise its a GP series. 8 | */ 9 | int main() 10 | { 11 | jaadu; 12 | uli a1,a2,a3; 13 | cin>>a1>>a2>>a3; 14 | while(a1!=0 || a2 !=0 || a3 !=0){ //Loop until the End of input (denoted by 0 0 0) 15 | 16 | if((a2-a1)==(a3-a2)){ //Check for AP Series 17 | cout<<"AP "<>a1>>a2>>a3; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Spoj_problems/ADDREV/problem.md: -------------------------------------------------------------------------------- 1 |

Problem Link

2 | Problem Link = https://www.spoj.com/problems/ADDREV/ 3 |
4 | Difficulty Level = Easy 5 |
6 | Problem Tag = #simple-math #ad-hoc-1 7 | -------------------------------------------------------------------------------- /Spoj_problems/CANDY/problem.md: -------------------------------------------------------------------------------- 1 |

Problem Link

2 | Problem Link = https://www.spoj.com/problems/CANDY/ 3 |
4 | Problem Tag = #ad-hoc-1 5 | -------------------------------------------------------------------------------- /Spoj_problems/FCTRL/problem.md: -------------------------------------------------------------------------------- 1 |

Problem Link

2 | Problem Link = https://www.spoj.com/problems/FCTRL/ 3 |
4 | Difficulty Level = Easy 5 |
6 | Problem Tag = #math 7 | -------------------------------------------------------------------------------- /Spoj_problems/FCTRL2/problem.md: -------------------------------------------------------------------------------- 1 |

Problem Link

2 | Problem Link = https://www.spoj.com/problems/FCTRL2/ 3 |
4 | Problem Tag = #math #big-numbers 5 | -------------------------------------------------------------------------------- /Spoj_problems/NSTEPS/problem.md: -------------------------------------------------------------------------------- 1 |

Problem Link

2 | Problem Link = https://www.spoj.com/problems/NSTEPS/ 3 |
4 | Problem Tag = #ad-hoc-1 5 | -------------------------------------------------------------------------------- /Spoj_problems/ONP/problem.md: -------------------------------------------------------------------------------- 1 |

Problem Link

2 | Problem Link = https://www.spoj.com/problems/ONP/ 3 |
4 | Problem Tag = #stack 5 | -------------------------------------------------------------------------------- /Spoj_problems/PRIME1/problem.md: -------------------------------------------------------------------------------- 1 |

Problem Link

2 | Problem Link = https://www.spoj.com/problems/PRIME1/ 3 |
4 | Problem Tag = #number-theory 5 | -------------------------------------------------------------------------------- /Spoj_problems/SAMER08F/problem.md: -------------------------------------------------------------------------------- 1 |

Problem Link

2 | Problem Link = https://www.spoj.com/problems/SAMER08F/ 3 |
4 | Problem Level = Easy 5 | -------------------------------------------------------------------------------- /Spoj_problems/SAMER08F/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define jaadu ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 4 | typedef unsigned long long int uli; 5 | /* 6 | This method calculates no. of different squares in a given grid of N*N squares. 7 | The end of input is indicated by a line containing only one zero. 8 | This problem can also be solved using dp using eq => F(n) = n*2 + F(n-1) where F(1) = 1 9 | However here we will use a simple formula. 10 | i.e., Sum of Squares = n*(n+1)*(2n+1)/6 11 | */ 12 | int main() 13 | { 14 | jaadu; 15 | int n; 16 | cin>>n; 17 | while(n!= 0){ 18 | cout<<(n)*(n+1)*(2*n + 1)/6<>n; 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Spoj_problems/TEST/problem.md: -------------------------------------------------------------------------------- 1 |

Problem Link

2 | Problem Link = https://www.spoj.com/problems/TEST/ 3 |
4 | Difficulty Level = Easy 5 | -------------------------------------------------------------------------------- /Spoj_problems/TEST/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | /* It's a simple problem focusing on I/O. 4 | Continuously take input from user until it reads the number 42 and print the numbers. 5 | Problem Tag: #basic #tutorial #ad-hoc-1 6 | */ 7 | int main() 8 | { 9 | int s; 10 | cin>>s; 11 | while(s!=42) 12 | { 13 | cout<>s; 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /project_euler_problems/10001st prime/problem.md: -------------------------------------------------------------------------------- 1 | # 10001st prime 2 | 3 | ## Project Euler 4 | 5 | ## Problem link : https://projecteuler.net/problem=7 6 | 7 | > By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. 8 | > 9 | > What is the 10 001st prime number? 10 | 11 | ## Resources 12 | 13 | - [Prime Number (Wikipedia)](https://en.wikipedia.org/wiki/Prime_number#Definition_and_examples) 14 | -------------------------------------------------------------------------------- /project_euler_problems/CountingSundays/problem.md: -------------------------------------------------------------------------------- 1 | https://projecteuler.net/problem=19 2 | -------------------------------------------------------------------------------- /project_euler_problems/EvenFibonacciNumbers/problem.md: -------------------------------------------------------------------------------- 1 | https://projecteuler.net/problem=2 2 | -------------------------------------------------------------------------------- /project_euler_problems/EvenFibonacciNumbers/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | // even fibonacci numbers from Project Euler 3 | 4 | int main() 5 | { 6 | int firstTerm {1}; 7 | int secondTerm {2}; 8 | int tempTerm {0}; 9 | 10 | long sum {0}; 11 | 12 | while (secondTerm <= 4000000){ 13 | 14 | // only count even fibonacci numbers toward our sum 15 | if (secondTerm % 2 == 0) 16 | sum += secondTerm; 17 | 18 | // for the next loop, firstTerm is equal to the previous second 19 | // and second is equal to the sum of the current two terms 20 | tempTerm = secondTerm; 21 | secondTerm += firstTerm; 22 | firstTerm = tempTerm; 23 | } 24 | 25 | std::cout << "Sum of even fibonacci numbers <= 4 million: " << sum << std::endl; 26 | 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /project_euler_problems/SumSquareDifference/problem.md: -------------------------------------------------------------------------------- 1 | https://projecteuler.net/problem=6 2 | -------------------------------------------------------------------------------- /project_euler_problems/digit factorials/problem.md: -------------------------------------------------------------------------------- 1 | # Digit Factorials 2 | 3 | ## Project Euler 4 | 5 | ## Problem link : https://projecteuler.net/problem=34 6 | -------------------------------------------------------------------------------- /project_euler_problems/integer right triangle/problem.md: -------------------------------------------------------------------------------- 1 | # Integer Right triangle 2 | 3 | ## Project Euler 4 | 5 | ## Problem link : https://projecteuler.net/problem=39 6 | -------------------------------------------------------------------------------- /project_euler_problems/lattice paths/problem.md: -------------------------------------------------------------------------------- 1 | # Lattice paths 2 | 3 | ## Project Euler 4 | 5 | ## Problem link : https://projecteuler.net/problem=15 6 | 7 | > Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner. 8 | > 9 | > How many such routes are there through a 20×20 grid? 10 | 11 | ## Resources 12 | 13 | - [Binomial distribution (Wikipedia)](https://en.wikipedia.org/wiki/Binomial_distribution) 14 | - [Lattice path (Wikipedia)](https://en.wikipedia.org/wiki/Lattice_path) 15 | -------------------------------------------------------------------------------- /project_euler_problems/summation of primes/problem.md: -------------------------------------------------------------------------------- 1 | # Summation of primes 2 | 3 | ## Project Euler 4 | 5 | ## Problem link : https://projecteuler.net/problem=10 6 | 7 | > The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. 8 | > 9 | > Find the sum of all the primes below two million. 10 | 11 | ## Resources 12 | 13 | - [Prime Number (Wikipedia)](https://en.wikipedia.org/wiki/Prime_number#Definition_and_examples) 14 | --------------------------------------------------------------------------------