├── .github ├── config.yml └── stale.yml ├── .mergify.yml ├── Assets └── images │ ├── announcement.png │ ├── github1.png │ ├── github2.png │ ├── github3.png │ ├── github4.png │ └── github5.png ├── AtCoder └── Staircase Sequences │ ├── readme.md │ └── solution.cpp ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── CP-DSA_RESOURCES.md ├── Codechef ├── A Problem on Sticks │ ├── readme.md │ ├── solution.cpp │ ├── solution.py │ └── solution2.py ├── ATM │ ├── readme.md │ └── solution.cpp ├── Add and Divide │ ├── readme.md │ └── solution.cpp ├── Airline │ ├── airline.cpp │ └── readme.md ├── Alice and Bob faceoff │ ├── readme.md │ └── solution.cpp ├── Alternative Square Pattern │ ├── README.md │ └── solution.cpp ├── Birthday Gifts │ ├── readme.md │ └── solution.py ├── Bus full of passengers │ ├── readme.md │ └── solution.cpp ├── Cars and Bikes │ ├── Readme.md │ └── Solution.java ├── Chef and Easy Queries │ ├── Readme.md │ └── Solution.py ├── Chef and Linear Chess │ ├── Readme.md │ └── Solution.py ├── Chef and Price Control │ ├── Readme.md │ └── Solution.py ├── Chef and Steps │ ├── readme.md │ └── solution.cpp ├── Chef and Street Food │ ├── readme.md │ └── solution.cpp ├── Chef and Two Strings │ ├── readme.md │ └── solution.py ├── Counting Pretty Numbers │ ├── readme.md │ └── solution.py ├── Cutting Recipes │ ├── readme.md │ └── solution.cpp ├── Daigonal movement │ ├── readme.md │ └── solution.cpp ├── Different String │ ├── readme.md │ └── solution.cpp ├── Doctor Chef │ ├── readme.md │ └── solution.cpp ├── Equal Difference │ ├── readme.md │ └── solution.cpp ├── Factors Finding │ ├── README.md │ └── solution.cpp ├── Find the direction │ ├── readme.md │ └── solution.cpp ├── Fix number of fix points │ ├── readme.md │ └── solution.cpp ├── GCD and LCM │ ├── readme.md │ └── solution.cpp ├── Golf │ ├── readme.md │ └── solution.cpp ├── Greedy Puppy │ ├── readme.md │ └── solution.cpp ├── Highest Divisor │ ├── readme.md │ └── solution.cpp ├── Interesting Representation │ ├── Readme.md │ └── solution.cpp ├── Kitchen TimeTable │ ├── readme.md │ └── solution.cpp ├── Magical Doors │ ├── readme.md │ └── solution.cpp ├── Make it Divisible │ ├── readme.md │ └── solution.cpp ├── Marathon │ ├── readme.md │ └── solution.py ├── Maximise the Subsequence Sum │ ├── readme.md │ └── solution.cpp ├── Maximum Array Xor │ ├── readme.md │ └── solution.cpp ├── Maximum Weight Difference │ ├── readme.md │ └── solution.java ├── Minimize the digit Sum │ ├── readme.md │ └── solution.cpp ├── Mod Equality │ ├── readme.md │ └── solution.cpp ├── No Time To Wait │ ├── readme.md │ └── solution.cpp ├── Odd gcd │ ├── readme.md │ └── solution.cpp ├── Olympics Ranking │ ├── readme.md │ └── solution.cpp ├── Prefix Sums │ ├── readme.md │ └── solution.cpp ├── Problem Difficulties │ ├── readme.md │ └── solution.cpp ├── RCB and Playoffs │ ├── readme.md │ └── solution.cpp ├── Remove One Element │ ├── readme.md │ └── solution.cpp ├── Reverse a Number │ ├── readme.md │ └── solution.py ├── Shoe Fit │ ├── readme.md │ └── solution.cpp ├── Shortest route │ ├── SHROUTE.cpp │ └── readme.md ├── Small Factorial │ ├── readme.md │ └── solution.cpp ├── Smallest Pair │ ├── readme.md │ └── solution.cpp ├── Splitting Candies │ ├── Solution.java │ └── readme.md ├── Tanu and Head-bob │ ├── readme.md │ └── solution.cpp ├── The grid fill problem │ ├── readme.md │ └── solution.cpp ├── Total Expenses │ ├── readme.md │ └── solution.cpp ├── Travel Pass │ ├── readme.md │ └── solution.py ├── Two Dishes │ ├── readme.md │ └── solution.cpp ├── Vaccine Dates │ ├── readme.md │ └── solution.cpp ├── Which_Mixture │ ├── README.md │ └── Solution.cpp ├── longest and subarray │ ├── readme.md │ └── solution.cpp └── three boxes │ ├── readme.md │ └── threeboxes.cpp ├── Codeforces ├── Productive Meeting │ ├── readme.md │ └── solution.cpp ├── A-Puzzles │ ├── readme.md │ └── solution.cpp ├── AND OR and square sum │ └── solution.cpp ├── AND OR and square sum │ └── readme.md ├── Almost All Divisors │ ├── readme.md │ └── solution.cpp ├── BackSpace │ ├── readme.md │ └── solution.cpp ├── Bakry-and-Partitioning │ ├── readme.md │ └── solution.cpp ├── Balanced team │ ├── readme.md │ └── solution.cpp ├── Beautiful Matrix │ ├── README.md │ └── Solution.cpp ├── Borze │ ├── readme.md │ └── solution.cpp ├── Boys and Girls │ ├── readme.md │ └── solution.cpp ├── CQXYM Count Permutations │ ├── readme.md │ └── solution.cpp ├── Card Constructions │ ├── readme.md │ └── solution.cpp ├── CasimirsStringSolitaire │ ├── readme.md │ └── solution.cpp ├── Cherry │ ├── readme.md │ └── solution.cpp ├── ChessTournament │ ├── readme.md │ └── solution.cpp ├── Coin Rows │ ├── readme.md │ └── solution.cpp ├── Complicated GCD │ ├── readme.md │ └── solution.cpp ├── Create The Teams │ ├── readme.md │ └── solution.py ├── Customising the Track │ ├── readme.md │ └── solution.cpp ├── Diameter of Graph │ ├── readme.md │ └── solution.cpp ├── Dice Tower │ ├── readme.md │ └── solution.cpp ├── Die Roll │ ├── Die Roll.cpp │ └── readme.md ├── Divide by three, multiply by two │ ├── readme.md │ └── solution.py ├── Do Not Be Distracted! │ ├── readme.md │ └── solution.cpp ├── Dominant Piranha │ ├── readme.md │ └── solution.cpp ├── Déjà Vu │ ├── Déjà Vu.cpp │ └── readme.md ├── E-Permutation Minimization │ ├── readme.md │ └── solution.cpp ├── Effective Approach │ ├── readme.md │ └── solution.cpp ├── Find The Array │ ├── README.md │ └── solution.java ├── GCD Sum │ ├── README.md │ └── solution.py ├── GameWithArray │ ├── README.md │ └── Solution.cpp ├── Hit Lottery │ ├── README.md │ └── hitthelottery.cpp ├── Inconvinient Pairs │ ├── readme.md │ └── solution.cpp ├── Infinity Table │ ├── Infinity Table.cpp │ └── README.md ├── Is your horseshoe on the other hoof │ ├── readme.md │ └── solution.cpp ├── K Divisible Sum │ ├── readme.md │ └── solution.cpp ├── Kayaking │ ├── readme.md │ └── solution.cpp ├── Lucky Mask │ ├── README.md │ └── solution.py ├── LuxiriousHouse │ ├── readme.md │ └── solution.cpp ├── MAX-MEX Cut │ ├── MAX-MEX_Cut.cpp │ └── Readme.md ├── MIN-MEX Cut │ ├── readme.md │ └── solution.cpp ├── Median Maximization │ ├── readme.md │ └── solution.cpp ├── Mocha and Hiking │ ├── README.md │ └── mocha_and_hiking.cpp ├── Multiply by two divide by six │ ├── README.md │ └── solution.py ├── National Project │ ├── readme.md │ └── solution.cpp ├── Nearly Lucky Number │ ├── README.md │ └── solution.cpp ├── Non-zero │ ├── readme.md │ └── solution.cpp ├── Permutation Minimization by Deque │ ├── readme.md │ └── solution.cpp ├── QAQ │ ├── readme.md │ └── solution.cpp ├── Queue at the School │ ├── readme.md │ └── solution.cpp ├── Regular Bracket Sequences │ ├── readme.md │ └── solution.cpp ├── Scenes From a Memory │ ├── readme.md │ └── solution.cpp ├── Seating Arrangements hard version │ ├── readme.md │ └── solutions.cpp ├── Semifinals │ ├── readme.md │ └── soultion.cpp ├── Spreadsheets │ ├── readme.md │ └── solution.cpp ├── T-Primes │ ├── Readme.md │ └── solution.cpp ├── The Miracle and the Sleeper │ ├── The Miracle and the Sleeper.cpp │ └── readme.md ├── Train-Maintenance │ ├── readme.md │ └── solution.cpp ├── Tram │ ├── readme.md │ └── solution.cpp ├── Tricks │ ├── readme.md │ └── solution.cpp ├── Two Platforms │ ├── readme.md │ └── solution.cpp ├── Two Round Dances │ ├── readme.md │ └── solution.cpp ├── Way Too Long Words │ ├── readme.md │ └── solution.cpp ├── Wizard of Orz │ ├── readme.md │ └── solution.cpp ├── Yet Another Card Deck │ ├── readme.md │ └── solution.cpp ├── Young Photographer │ ├── readme.md │ └── solution.cpp ├── Young Physicist │ ├── readme.md │ └── solution.cpp └── cupboards │ ├── readme.md │ └── solution.cpp ├── GeeksForGeeks ├── Check for BST │ ├── readme.md │ └── solution.cpp ├── Check if the door is open or closed │ ├── readme.md │ └── solution.cpp ├── Check whether two strings are anagram of each other │ ├── readme.md │ └── solution.cpp ├── Chocolate Distribution Problem │ ├── readme.md │ └── solution.cpp ├── Convert Binary Tree to BST │ ├── Readme.md │ └── Solution.py ├── Count-triplets-sorted-doubly-linked-list-whose-sum-equal-given-value-x │ ├── Readme.md │ └── Sollution.cpp ├── Detect Loop in linked list │ ├── Readme.md │ └── sollution.cpp ├── Detect cycle in an undirected graph │ ├── readme.md │ └── solution.cpp ├── Detect cycle in undirected graph │ ├── readme.md │ └── solution.java ├── Factorial of Large Numbers │ ├── readme.md │ └── solution.cpp ├── Given a linked list of 0s, 1s and 2s, sort it │ ├── Readme.md │ └── Sollution.cpp ├── Goldmine Problem │ ├── README.md │ └── solution.cpp ├── Intersection Point in Y Shapped ll │ ├── readme.md │ └── sollution.cpp ├── Intersection of arrays │ ├── README.md │ └── Solution.cpp ├── Kadanes Algorithm │ ├── readme.md │ └── solution.java ├── Longest consecutive subsequence │ ├── readme.md │ └── solution.cpp ├── Lowest Common Ansector │ ├── readme.md │ ├── solution.cpp │ └── solution2.cpp ├── Median of 2 Sorted Arrays of Different Sizes │ ├── readme.md │ └── solution.java ├── Merge Without Extra Space │ ├── README.md │ ├── solution.cpp │ └── solution.java ├── Preorder to Postorder │ ├── README.md │ └── Solution.java ├── Print Anagrams Together │ ├── readme.md │ └── solution.java ├── Remove Loop in Linked List │ ├── readme.md │ └── solution.cpp ├── Reverse a string using stack │ ├── readme.md │ └── solution.cpp ├── Segmented Sieve │ ├── readme.md │ └── solution.cpp ├── Sieve of Erastosthenes │ ├── Solution.cpp │ └── readme.md ├── Sort accoridng to frequency │ ├── readme.md │ └── solution.cpp └── Sort an array of 0s 1s and 2s │ ├── readme.md │ └── solution.cpp ├── Hackerearth ├── Alice and candies │ ├── readme.md │ ├── solution.cpp │ └── solution2.cpp ├── Balancing cubes │ ├── readme.md │ └── solution.cpp ├── Counting Frog Paths │ ├── readme.md │ └── solution.py ├── Likeable arrays │ ├── readme.md │ └── solution.cpp ├── Lunchboxes │ ├── readme.md │ └── solution.cpp ├── Maximum Sum │ ├── readme.md │ └── solution.cpp ├── Minimum Length │ ├── readme.md │ └── solution.cpp ├── Non-decreasing arrays │ ├── READme.md │ └── Solution.cpp ├── Pizza Confusion │ ├── readme.md │ └── solution.cpp ├── The Best Player │ ├── readme.md │ └── solution.cpp └── Zero subarray │ ├── readme.md │ └── solution.cpp ├── Hackerrank ├── 3D Surface area │ ├── README.md │ └── solution.cpp ├── A Very Big Sum │ ├── README.md │ └── solution2.cpp ├── ACM ICPC Team │ ├── readme.md │ └── solution.cpp ├── AND Product │ ├── and_product.cpp │ └── readme.md ├── Angry Professor │ ├── readme.md │ ├── solution.cpp │ ├── solution.java │ └── solution.py ├── Apple and Orange │ ├── Apple and Orange.py │ ├── README.md │ └── solution.js ├── Array Left Rotation │ ├── README.md │ └── Solution.cpp ├── Array Manipulation │ ├── README.md │ └── solution.cpp ├── Array Reversal │ ├── README.md │ └── solution.c ├── Balanced Brackets │ ├── readme.md │ └── solution.cpp ├── Beautiful Pairs │ ├── Readme.md │ └── solution.cpp ├── Beautiful Triplets │ ├── README.md │ └── solution.cpp ├── Bigger is Greater │ ├── readme.md │ └── solution.cpp ├── Bill Division │ ├── Solution.java │ └── readme.md ├── Birthday Cake Candles │ ├── README.md │ └── solution.c ├── CPP Variadics │ ├── readme.md │ └── solution.cpp ├── Caesar Cipher │ ├── readme.md │ └── solution.cpp ├── CamelCase │ ├── readme.md │ └── solution.cpp ├── Climbing the Leaderboard │ ├── readme.md │ └── solution.cpp ├── Cycle Detection │ ├── readme.md │ └── solution.cpp ├── Day of a Programmer │ ├── readme.md │ └── solution.cpp ├── Day of the programmer │ ├── readme.md │ ├── solution.c │ ├── solution2.cpp │ └── solution3.py ├── Dequeue STL │ ├── Solution.cpp │ └── readme.md ├── Designer Door Mat │ ├── Readme.md │ └── Solution.py ├── Designer PDF Viewer │ ├── README.md │ └── solution.cpp ├── Diagonal Difference │ ├── readme.md │ └── solution.py ├── DigitFrequency │ ├── readme.md │ └── solution.c ├── Drawing Book │ ├── solution.cpp │ └── solution2.cpp ├── Electronics Shop │ ├── README.md │ └── solution.py ├── Encryption │ ├── README.md │ └── solution.cpp ├── Equalize the Array │ ├── README.md │ └── solution.cpp ├── FairRations │ ├── readme.md │ └── solution.cpp ├── Find the Median │ ├── README.md │ └── findTheMedian.cpp ├── Find the Runner-Up Score │ ├── readme.md │ └── solution.py ├── Find the running median │ ├── readme.md │ └── solution.cpp ├── Flatland Space Stations │ ├── readme.md │ └── solutions.cpp ├── Flipping bits │ ├── README.md │ └── solution.cpp ├── For Loops │ ├── readme.md │ └── solution.cpp ├── Forming a Magic Square │ ├── readme.md │ └── solution.cpp ├── Funny String │ ├── README.md │ └── solution.cpp ├── Grading Students │ ├── Grading Students.py │ └── README.md ├── GreedyFlorist │ ├── GreedyFloristsol.cpp │ └── Readme.md ├── Grid Challenge │ ├── readme.md │ └── solution.c ├── Hackerland Radio Transmitters │ ├── readme.md │ └── solution.cpp ├── Hello World │ ├── readme.md │ └── solution.py ├── Ice Cream Parlor │ ├── README.md │ └── solution.cpp ├── Jumping on the Clouds │ ├── README.md │ └── solution.cpp ├── Larry's Array │ ├── readme.md │ ├── solution.cpp │ └── solution2.cpp ├── List Comprehensions │ ├── README.md │ └── solution.py ├── Mars Exploration │ ├── README.md │ └── solution.cpp ├── Merge the Tools │ ├── README.md │ └── solution.py ├── Messages Order │ ├── readme.md │ └── solution.cpp ├── Migratory Birds │ ├── README.md │ └── solution.py ├── Mini-Max Sum │ ├── readme.md │ └── solution.py ├── Minimum Distances │ ├── Readme.md │ └── solution.cpp ├── Multi Level Inheritance │ ├── README.md │ └── solution.cpp ├── New Companies │ ├── Readme.md │ └── Solution.sql ├── No Idea! │ ├── Readme.md │ └── Solution.py ├── Number Line Jumps │ ├── Number Line Jumps.py │ └── README.md ├── Pangrams │ ├── README.md │ └── solution.cpp ├── Picking Numbers │ ├── README.md │ └── solution.cpp ├── Pointers │ ├── readme.md │ └── solution.cpp ├── Printing Tokens │ ├── README.md │ └── solution.c ├── Reverse Linked List │ ├── readme.md │ └── solution.py ├── Running Time of Algorithms │ ├── README.md │ └── solution.cpp ├── Sales by Match │ ├── README.md │ ├── solution.cpp │ └── solution.py ├── Sherl │ ├── readme.md │ └── solution.cpp ├── SherlockAnagram │ ├── readme.md │ └── solution.cpp ├── Shrelock and Arrays │ ├── readme.md │ └── solution.cpp ├── Sparse Arrays │ ├── README.md │ └── solution.cpp ├── Staircase │ ├── README.md │ └── solution.cpp ├── Strange Counter │ ├── readme.md │ └── solution.cpp ├── Sum of Digits of a Five Digit Number │ ├── README.md │ └── solution.c ├── Swap Nodes │ ├── readme.md │ └── solution.cpp ├── Time Conversion │ ├── read.md │ └── solution.cpp ├── Variable Sized Arrays │ ├── README.md │ └── solution.cpp ├── Whats Your Name │ ├── readme.md │ └── solution.py ├── Write a Function │ ├── readme.md │ └── solution.py ├── Zig Zag Sequence │ ├── readme.md │ └── solution.cpp ├── compare-the-triplets │ ├── readme.md │ └── solution.py ├── drawingbook │ ├── README.md │ └── solution.py ├── kangaroo │ ├── readme.md │ ├── solution.py │ ├── solution1.py │ ├── solution2.cpp │ ├── solution3.py │ ├── solution4.py │ ├── solution5.cpp │ └── solution6.py └── polar coordinates │ ├── readme.md │ └── solution.py ├── InterviewBit ├── Best Time to Buy and Sell Stock atmost B times │ ├── readme.md │ └── solution.cpp ├── Fibonnacci Number │ ├── readme.md │ └── solution.cpp ├── Find Duplicate in Array │ ├── readme.md │ └── solution.cpp ├── Hotel Bookings Possible │ ├── readme.md │ └── solution.cpp ├── Max Product Subarray │ ├── readme.md │ └── solution.cpp ├── Max Sum Contiguous Subarray │ └── solution.cpp ├── Number of 1 bits │ ├── readme.md │ └── solution.cpp ├── Pick from both sides │ ├── readme.md │ └── solution.cpp ├── Rotated Sorted Array Search │ ├── readme.md │ └── solution.cpp └── find-duplicate-in-array │ ├── readme.md │ └── solution.cpp ├── LICENSE ├── Leetcode ├── Check If N and Its Double Exist │ ├── Solution.java │ ├── readme.md │ └── solution.cpp ├── 3 Sum Closest │ ├── readme.md │ └── solution.cpp ├── 3Sum │ ├── Readme.md │ └── solution.cpp ├── 4Sum │ ├── README.md │ ├── solution.cpp │ └── solution.java ├── All Possible Binary Trees │ ├── readme.md │ └── solution.cpp ├── Arithmetic Subarrays │ ├── readme.md │ └── solution.cpp ├── Best Time To Buy And Sell A Stock │ └── Solution2.cpp ├── Best Time to Buy and Sell Stock II │ ├── solution.cpp │ └── solution.java ├── Best Time to Buy and Sell Stock │ ├── Readme.md │ └── solution.cpp ├── Binary Subarrays With Sum │ ├── readme.md │ └── solution.cpp ├── Binary Tree Inorder Traversal │ ├── readme.md │ └── solution.cpp ├── Binary Tree Level Order Traversal │ ├── readme.md │ └── solution.cpp ├── Binary Tree Maximum Path Sum │ ├── readme.md │ └── solution.cpp ├── Binary Tree Pre Order Traversal │ ├── readme.md │ └── solution.cpp ├── Binary Tree post order traversal │ ├── readme.md │ └── solution.cpp ├── BinarySearch │ ├── Readme.md │ ├── solution.py │ └── solution2.cpp ├── Brick Wall │ ├── readme.md │ └── solution.cpp ├── Build Array from Permutation │ ├── README.md │ └── Solution.java ├── BustBalloon │ ├── readme.md │ └── solution.java ├── Buy And Sell Stock IV │ ├── readme.md │ └── solution.cpp ├── Candy │ ├── README.md │ └── Solution.cpp ├── Check If It Is a Straight Line │ ├── Readme.md │ └── solution.cpp ├── Climb Stairs │ ├── Readme.md │ └── solution.java ├── Coin Change Two │ ├── Readme.md │ └── Solution.java ├── Combination Sum iii │ ├── readme.md │ └── solution.cpp ├── Combination Sum │ ├── readme.md │ └── solution.cpp ├── Combinations │ ├── readme.md │ └── solution.cpp ├── Concatenation of Array │ ├── README.md │ └── Solution.java ├── Construct Binary Tree from Preorder and Inorder Traversal │ ├── readme.md │ └── solution.cpp ├── Container With Most Water │ ├── readme.md │ └── solution.cpp ├── Contains Duplicate │ ├── readme.md │ └── solution.py ├── Convert Sorted Array to Binary Search Tree │ ├── readme.md │ └── solution.cpp ├── Convert Sorted List to Binary Search Tree │ ├── readme.md │ └── solution.cpp ├── Copy list with random pointers │ ├── readme.md │ └── solution.cpp ├── Count Inversions │ ├── readme.md │ └── solution.cpp ├── Count Negative Numbers in a Sorted Matrix │ ├── readme.md │ └── solutions.java ├── Count Number Of Consistent Strings │ ├── readme.md │ └── solution.java ├── Count Numbers with Unique Digits │ ├── readme.md │ └── solution.cpp ├── Count Sorted Vowel Strings │ ├── readme.md │ └── solution.cpp ├── Count-good-triplets │ ├── readme.md │ └── solution.py ├── Course Schedule │ ├── readme.md │ └── solution.cpp ├── DailyTempratures │ ├── readme.md │ └── tempratures.cpp ├── Deepest Leaves Sum │ ├── readme.md │ └── solution.cpp ├── Delete Leaves with a given Value │ ├── readme.md │ └── solution.cpp ├── Diameter Of The Binary Tree │ ├── Readme.md │ └── solution.cpp ├── Distinct subsequences │ ├── readme.md │ └── solution.py ├── Dungeon Game │ ├── readme.md │ └── solution.cpp ├── Edit Distance │ ├── readme.md │ └── solution.cpp ├── Evaluate Reverse Polish Notation │ ├── readme.md │ └── solution.cpp ├── Fibonacci Number │ ├── Readme.md │ └── fibonacci.cpp ├── Final Prices With a Special Discount in a Shop │ ├── readme.md │ └── solution.cpp ├── Find First and Last Position of Element in Sorted Array │ ├── README.md │ └── Solution.cpp ├── Find Greatest Common Divisor of Array │ ├── Readme.md │ └── solution.cpp ├── Find K Closest Elements │ ├── Solution.java │ └── readme.md ├── Find Median from Data Stream │ ├── README.md │ └── Solution.cpp ├── Find Minimum in Rotated Sorted Array II │ ├── Readme.md │ └── solution.cpp ├── Find Minimum in Rotated Sorted Array │ ├── readme.md │ └── solution.cpp ├── Find Peak Element │ ├── Solution.java │ └── readme.md ├── Find Smallest Letter Greater Than Target │ ├── readme.md │ └── solution.java ├── Find all duplicates in an array │ ├── readme.md │ └── solution.java ├── Find first missing positive │ ├── readme.md │ └── solution.java ├── Find the Highest Altitude │ └── solution.cpp ├── Find the Middle Index in Array │ ├── readme.md │ └── solution.cpp ├── First Missing Positive │ ├── README.md │ └── solution.py ├── First unique character in sting │ ├── readme.md │ └── solution.py ├── Flipping an image │ ├── README.md │ ├── Solution.cpp │ └── Solution.java ├── Frog Jump │ ├── readme.md │ └── solution.cpp ├── Gas station │ ├── readme.md │ └── solution.cpp ├── Gray Code │ ├── readme.md │ └── solution.cpp ├── Group Anagrams │ ├── readme.md │ └── solution.cpp ├── Group the People Given the Group Size They Belong To │ ├── Readme.md │ └── solution.py ├── Happy Number │ ├── Readme.md │ └── solution.cpp ├── House Robber │ ├── House Robber.cpp │ ├── readme.md │ └── solution2.java ├── Implement strStr │ ├── readme.md │ └── solution.cpp ├── Increasing Triplet Subsequence │ ├── readme.md │ └── solution.cpp ├── Insert into a binary search tree │ ├── readme.md │ └── solution.cpp ├── Integer to English Words │ ├── README.md │ └── soluiton.cpp ├── Intersection of Two Arrays II │ ├── intersection_of_two_array.java │ ├── readme.md │ └── solution2.cpp ├── Is Graph Bipartite │ ├── README.md │ └── solution.cpp ├── Jump Game 2 │ ├── README.md │ └── solution.cpp ├── Jump Game │ ├── Solution.java │ ├── readme.md │ ├── solution.cpp │ └── solution2.cpp ├── K-Concatenation Maximum Sum │ ├── readme.md │ └── solution.cpp ├── K-th Symbol in Grammar │ ├── Readme.md │ └── Solution.java ├── Kids With the Greatest Number of Candies │ ├── readme.md │ └── solution.cpp ├── Koko eating bananas │ ├── Readme.md │ └── solution.cpp ├── Kth Smallest Element in a sorted Matrix │ ├── readme.md │ └── solution.cpp ├── LRU cache │ ├── readme.md │ └── solution.cpp ├── Largest Perimeter Triangle │ ├── Readme.md │ └── Solution.cpp ├── Largest Rectangle in Histogram │ ├── readme.md │ └── solution.cpp ├── Last Stone Weight │ ├── readme.md │ └── solution.cpp ├── Letter Combination of Phone number │ ├── Readme.md │ └── soluion.cpp ├── Linked List Cycle │ ├── readme.md │ └── solution.cpp ├── Longest Common Prefix │ ├── README.md │ ├── solution.cpp │ └── solution.java ├── Longest Consecutive Sequence │ ├── README.md │ └── solution.cpp ├── Longest Palindromic SubString │ ├── readme.md │ └── solution.cpp ├── Longest Subarray of 1's After Deleting One Element │ ├── README.md │ └── solution.cpp ├── Longest Substring Without Repeating Characters │ ├── README.md │ └── solution.py ├── LongestPalindromicSubsequence │ ├── readme.md │ └── solution.java ├── Lowest Common Ancestor of a Binary Search Tree │ ├── readme.md │ └── solution.cpp ├── Majority Element II │ ├── readme.md │ └── solution.cpp ├── Majority Element │ ├── readme.md │ └── solution.cpp ├── Matrix Diagonal Sum │ ├── readme.md │ └── solutuon.cpp ├── Max Area of Island │ ├── readme.md │ ├── solution.cpp │ └── soluton.java ├── Max Chunks To Make Sorted │ ├── README.md │ └── Solution.cpp ├── Max Increase to Keep City Skyline │ ├── Readme.md │ └── solution.py ├── Max Points on a Line │ ├── readme.md │ └── solution.cpp ├── Maximize Distance to Closest Person │ ├── README.md │ └── solution.cpp ├── Maximum Depth of Binary Tree │ ├── readme.md │ └── solution.cpp ├── Maximum Population Year │ ├── README.md │ └── solution.java ├── Maximum Product Subarray │ ├── readme.md │ └── solution.cpp ├── Maximum Product of Three Numbers │ ├── Readme.md │ └── Solution.cpp ├── Median of Two Sorted Arrays │ ├── Solution.java │ ├── Solution2.java │ └── Solution3.java ├── Merge In Between Linked Lists │ ├── readme.md │ └── solution.cpp ├── Merge Overlapping Subintervals │ ├── readme.md │ └── solution.cpp ├── Merge Sorted Array │ ├── readme.md │ └── solution.cpp ├── Merge Two Sorted Lists │ ├── readme.md │ └── solution.cpp ├── Merge k Sorted Lists │ ├── readme.md │ └── solution.cpp ├── Middle of the Linked List │ ├── readme.md │ └── solution.cpp ├── Min Cost Climbing Stairs │ ├── readme.md │ └── solution.cpp ├── Minimum Absolute Sum Difference │ ├── readme.md │ └── solution.cpp ├── Minimum Add to Make Parentheses Valid │ ├── readme.md │ └── solution.cpp ├── Minimum Cost to cut stick │ ├── readme.md │ └── solution.java ├── Minimum Depth of Binary Tree │ ├── Readme.md │ └── Solution.java ├── Minimum Height Trees │ ├── readme.md │ └── solution.cpp ├── Minimum Speed to Arrive on Time │ ├── Solution.java │ └── readme.md ├── Minimum Time to Type Word Using Special Typewriter │ ├── readme.md │ └── solution.cpp ├── Minimum Window Substring │ ├── readme.md │ └── solution.cpp ├── Missing Number │ ├── readme.md │ └── solution.cpp ├── MissingNumber │ ├── readme.md │ └── solution.java ├── Move Zeroes │ ├── readme.md │ └── solution.cpp ├── Multiply Strings │ ├── readme.md │ └── solution.cpp ├── N Queens │ ├── readme.md │ └── solution.cpp ├── N-Repeated Element in Size 2N Array │ ├── readme.md │ └── solution.cpp ├── Network Delay Time │ ├── readme.md │ └── solution.cpp ├── Next Greater Element II │ ├── readme.md │ └── solution.cpp ├── Nth Tribonacci Number │ ├── readme.md │ └── solution.cpp ├── Number Of Longest Increasing Subsequence │ ├── README.md │ └── solution.cpp ├── Number of BSTs │ ├── readme.md │ └── solution.java ├── Number of Good pairs │ ├── readme.md │ └── solution.java ├── Number of Islands │ ├── readme.md │ ├── solution.cpp │ └── solution2.java ├── Number of Pairs of Strings With Concatenation Equal to Target │ ├── readme.md │ └── solution.cpp ├── Number of Steps to Reduce a Number to Zero │ ├── readme.md │ └── solution.java ├── Number of Students Doing Homework at a Given Time │ ├── readme.md │ └── solution.cpp ├── Number of Substrings With Only 1s │ ├── readme.md │ └── solution.cpp ├── Odd Even Linked List │ ├── readme.md │ └── solution.cpp ├── Palindrome Number │ ├── readme.md │ ├── solution.c │ └── solution2.cpp ├── Palindrome Partitioning II │ ├── readme.md │ └── solution.cpp ├── Palindrome Partitioning │ ├── readme.md │ └── solution.cpp ├── Palindromic Substrings │ ├── readme.md │ └── solution.cpp ├── Partition Equal Subset Sum │ ├── readme.md │ └── solution.cpp ├── Partition array for Maximum Sum │ ├── readme.md │ └── solution.cpp ├── Partition into K Equal Sum Subsets │ ├── Solution.java │ └── readme.md ├── Partition to K Equal Sum Subsets │ └── Partition Equal Subset Sum │ │ ├── Solution.cpp │ │ └── readme.md ├── Path Sum │ ├── Solution.cpp │ └── readme.md ├── Path With Minimum Effort │ ├── readme.md │ └── solution.cpp ├── Peak Index Mountain Array │ ├── README.md │ └── Solution.java ├── Permutation Sequence │ ├── readme.md │ └── solution.cpp ├── Permutations │ ├── readme.md │ └── solution.cpp ├── Plus One │ ├── readme.md │ ├── solution.py │ └── solution2.cpp ├── Pow-x-n │ ├── readme.md │ └── solution.cpp ├── Product of Array Except Self │ ├── Solution.java │ └── readme.md ├── Range sum of BST │ ├── readme.md │ └── solution.py ├── Regular Expression Matching │ ├── readme.md │ └── solution.cpp ├── Remove All Adjacent Duplicates In String │ ├── readme.md │ └── solution.cpp ├── Remove Duplicates from Sorted Array │ ├── Readme.md │ └── solution.py ├── Remove Element │ ├── readme.md │ └── solution.cpp ├── Remove Nth Node From End of List │ ├── readme.md │ └── solution.cpp ├── Reorder List │ ├── readme.md │ └── solution.cpp ├── Reshape the Matrix │ ├── readme.md │ └── solution.cpp ├── Reverse Integer │ ├── README.md │ └── Solution.java ├── Reverse Linkedlist │ ├── readme.md │ └── solution.cpp ├── Richest Customer Wealth │ ├── README.md │ └── Solution.java ├── Roman to Integer │ ├── README.md │ └── solution.py ├── Rotate Image │ ├── readme.md │ └── solution.cpp ├── Rotate array to right │ ├── readme.md │ └── solution.cpp ├── Rotting Oranges │ ├── readme.md │ └── solution.cpp ├── Running Sum of 1d Array │ ├── README.md │ └── Solution.java ├── SINGLE NUMBER III │ ├── readme.md │ └── solution.cpp ├── Same Tree │ ├── readme.md │ ├── solution.java │ └── solution2.cpp ├── Search Insert Position II │ ├── README.md │ └── solution.java ├── Search Insert Position │ ├── Readme.md │ ├── Solution.java │ └── Solution.py ├── Search a 2D matrix │ ├── readme.md │ └── solution.cpp ├── Search in a 2D Matrix │ ├── readme.md │ └── solution.cpp ├── Search in a Binary Search Tree │ ├── README.md │ └── solution.java ├── Search in rotated sorted array │ ├── readme.md │ └── solution.cpp ├── Set Matrix Zeroes │ ├── readme.md │ └── solution.py ├── Set Mismatch │ ├── readme.md │ └── solution.java ├── Shortest Path in a Grid with Obstacles Elimination │ ├── readme.md │ └── solution.cpp ├── Shuffle String │ ├── readme.md │ └── solution.cpp ├── Shuffle the Array │ ├── Solution.java │ └── readme.md ├── Sign of the Product of an Array │ ├── Readme.md │ └── Solution.cpp ├── Simplify Path │ ├── readme.md │ └── solution.cpp ├── Single Number │ ├── readme.md │ └── solution.cpp ├── Single element in a sorted array │ ├── readme.md │ └── solution.java ├── Sort Array By Parity │ ├── Solution.cpp │ └── readme.md ├── Sort colors │ ├── Readme.md │ ├── Solution.cpp │ └── solution.java ├── Sort the Matrix Diagonally │ ├── Readme.md │ └── solution.py ├── Spiral Matrix │ ├── readme.md │ └── solution.java ├── Split Array Largest Sum │ ├── readme.md │ └── solution.cpp ├── Split Linked List in Parts │ ├── readme.md │ └── solution.cpp ├── Sqrt-x │ ├── Readme.md │ └── Solution.cpp ├── Sqrtx │ ├── readme.md │ └── solution.cpp ├── Strong Password Checker │ ├── readme.md │ └── solution.py ├── Subarray Sum Equals k │ ├── readme.md │ └── solution.cpp ├── Subarray Sums Divisible by K │ ├── readme.md │ └── solution.cpp ├── Subarrays with K Different Integers │ ├── readme.md │ └── solution.cpp ├── Subtract the Product and Sum of Digits of an Integer │ ├── readme.md │ └── solution.java ├── Swim in rising water │ ├── Solution.java │ └── readme.md ├── Symmetric Tree │ ├── readme.md │ └── solution.cpp ├── Task Scheduler │ ├── README.md │ └── solution.py ├── TaskScheduler │ ├── README.md │ └── solution.py ├── The Skyline Problem │ ├── readme.md │ └── solution.cpp ├── Transform to Chessboard │ ├── readme.md │ └── solution.java ├── Trapping rain water │ ├── readme.md │ ├── solution.java │ └── solution2.cpp ├── Triangle │ ├── readme.md │ └── solution.cpp ├── Truncate Sentence │ ├── readme.md │ ├── solution.cpp │ └── solutuon2.cpp ├── TwoSum │ ├── readme.md │ ├── solution.cpp │ ├── solution.py │ └── solution2.cpp ├── Unique Paths II │ ├── readme.md │ └── solution.cpp ├── Unique Paths │ ├── readme.md │ └── solution.cpp ├── Unqiue Binary Search Trees │ ├── readme.md │ └── solution.cpp ├── Valid Anagram │ ├── README.md │ └── solution.java ├── Valid Mountain Array │ ├── readme.md │ └── solution.py ├── Valid parentheses │ ├── readme.md │ └── solution.cpp ├── Validate Binary Search Tree │ ├── readme.md │ └── solution.cpp ├── Word Search │ ├── readme.md │ └── solution.cpp ├── XOR Queries of a Subarray │ ├── readme.md │ └── solution.cpp ├── XOR operation in an array │ ├── readme.md │ └── solution.cpp ├── airplane seat assignment probablity │ ├── readme.md │ └── solution.cpp ├── base 7 │ ├── readme.md │ └── solution.cpp ├── find the highest altitude │ └── Solution.java ├── graph clone │ ├── readme.md │ └── solution.cpp ├── subsets │ ├── readme.md │ └── solution.cpp └── verify an alien dictionary │ ├── readme.md │ └── solution.cpp ├── MAKING_A_PR.md ├── PULL_REQUEST_TEMPLATE.md ├── README.md └── URIOnlineJudge ├── Carnaval ├── readme.md └── solution.java ├── Dancing sentence ├── readme.md └── solution.py ├── Maesters Map ├── readme.md └── solution.cpp ├── Sorting Santa List of Children ├── Readme.md └── solution.py ├── The change ├── readme.md └── solution.cpp └── Triangle ├── Readme.md └── solution.py /.github/config.yml: -------------------------------------------------------------------------------- 1 | newPRWelcomeComment: "Congrats on submitting your first Pull Request here! :tada: :tada: \nYour PR would be reviewed by a maintainer soon :heavy_check_mark: \nIn the meantime, :star: star this repo and check out our [Instagram](https://www.instagram.com/tle.mec/) page if you wanna learn more about CP & DSA! :smiley:" 2 | 3 | -------------------------------------------------------------------------------- /Assets/images/announcement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TLE-MEC/Hack-CP-DSA/44d8e9de034a27c0311d0d261958bf7d17cad55a/Assets/images/announcement.png -------------------------------------------------------------------------------- /Assets/images/github1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TLE-MEC/Hack-CP-DSA/44d8e9de034a27c0311d0d261958bf7d17cad55a/Assets/images/github1.png -------------------------------------------------------------------------------- /Assets/images/github2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TLE-MEC/Hack-CP-DSA/44d8e9de034a27c0311d0d261958bf7d17cad55a/Assets/images/github2.png -------------------------------------------------------------------------------- /Assets/images/github3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TLE-MEC/Hack-CP-DSA/44d8e9de034a27c0311d0d261958bf7d17cad55a/Assets/images/github3.png -------------------------------------------------------------------------------- /Assets/images/github4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TLE-MEC/Hack-CP-DSA/44d8e9de034a27c0311d0d261958bf7d17cad55a/Assets/images/github4.png -------------------------------------------------------------------------------- /Assets/images/github5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TLE-MEC/Hack-CP-DSA/44d8e9de034a27c0311d0d261958bf7d17cad55a/Assets/images/github5.png -------------------------------------------------------------------------------- /AtCoder/Staircase Sequences/readme.md: -------------------------------------------------------------------------------- 1 | # Staircase Sequences 2 | 3 | ## Contest: AtCoder Beginner Contest 190 4 | 5 | ## problem link: https://atcoder.jp/contests/abc190/tasks/abc190_d 6 | -------------------------------------------------------------------------------- /Codechef/A Problem on Sticks/readme.md: -------------------------------------------------------------------------------- 1 | # PROBLEMLINK 2 | 3 | https://www.codechef.com/SEPT20B/problems/TREE2 4 | 5 | Level: Beginner 6 | -------------------------------------------------------------------------------- /Codechef/A Problem on Sticks/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t;//number of test cases 6 | cin>>t; 7 | while(t--){ 8 | int n;//input the number of sticks 9 | cin>>n; 10 | int a[n],i;// for each valid i, the initial height of the stick in the i-th holder is A[i] 11 | sets; 12 | for( i=0;i>a[i]; 14 | } 15 | for( i=0;i0) 11 | { 12 | int n=sc.nextInt();//Inputting number of tyres 13 | if(n%4!=0)//if number of tyres are divisible by 4 then there can't be any bike 14 | System.out.println("YES"); 15 | else 16 | System.out.println("NO"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Codechef/Chef and Easy Queries/Readme.md: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/OCT20B/problems/CHEFEZQ 2 | 3 | Level : Easy -------------------------------------------------------------------------------- /Codechef/Chef and Linear Chess/Readme.md: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/AUG20B/problems/LINCHESS -------------------------------------------------------------------------------- /Codechef/Chef and Price Control/Readme.md: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/JUNE20B/problems/PRICECON 2 | 3 | Level : Easy -------------------------------------------------------------------------------- /Codechef/Chef and Price Control/Solution.py: -------------------------------------------------------------------------------- 1 | # Taking Testcases as Input 2 | t = int(input()) 3 | for i in range(t): 4 | # Taking n and k as input 5 | n,k = map(int,input().split()) 6 | # taking array that is used to find the revenue as input 7 | p = list(map(int,input().strip().split()))[:n] 8 | rev = 0 9 | # for each prices in the array,reduce it by k and increment in the answer 10 | for i in range(n): 11 | if p[i]>k: 12 | rev += p[i]-k 13 | print (rev) -------------------------------------------------------------------------------- /Codechef/Chef and Steps/readme.md: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/LTIME86B/problems/CHEFSTEP -------------------------------------------------------------------------------- /Codechef/Chef and Street Food/readme.md: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/LRNDSA02/problems/STFOOD -------------------------------------------------------------------------------- /Codechef/Chef and Two Strings/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Beginner 2 | Link to the problem: https://www.codechef.com/problems/CHEFSTLT -------------------------------------------------------------------------------- /Codechef/Counting Pretty Numbers/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Beginner 2 | Link to the problem: https://www.codechef.com/problems/NUM239 -------------------------------------------------------------------------------- /Codechef/Counting Pretty Numbers/solution.py: -------------------------------------------------------------------------------- 1 | '''Approach: Count numbers which have last digit as 2,3 or 9 which can be found by num % 10 unit digit''' 2 | 3 | 4 | 5 | # cook your code here 6 | t = int(input()) 7 | while(t): 8 | l,r = map(int,raw_input().split()) 9 | l_d = 0 10 | c = 0 11 | for i in range(l,r+1): 12 | l_d = i % 10 13 | if(l_d == 2 or l_d == 3 or l_d == 9): 14 | c += 1 15 | print(c) 16 | t -= 1 17 | 18 | -------------------------------------------------------------------------------- /Codechef/Cutting Recipes/readme.md: -------------------------------------------------------------------------------- 1 | Link : https://www.codechef.com/problems/RECIPE -------------------------------------------------------------------------------- /Codechef/Daigonal movement/readme.md: -------------------------------------------------------------------------------- 1 | # PROBLEMLINK 2 | 3 | https://www.codechef.com/START14B/problems/DIAGMOVE/ 4 | 5 | Level: Beginner -------------------------------------------------------------------------------- /Codechef/Different String/readme.md: -------------------------------------------------------------------------------- 1 | ## PROBLEM LINK 2 | 3 | https://www.codechef.com/COOK132C/problems/DIFSTR/ 4 | 5 | Level: Easy 6 | -------------------------------------------------------------------------------- /Codechef/Doctor Chef/readme.md: -------------------------------------------------------------------------------- 1 | ## PROBLEM LINK 2 | 3 | https://www.codechef.com/problems/DRCHEF 4 | -------------------------------------------------------------------------------- /Codechef/Equal Difference/readme.md: -------------------------------------------------------------------------------- 1 | ## PROBLEM LINK FOR EQUAL DIFFERENCE 2 | 3 | https://www.codechef.com/COOK132B/problems/EQDIFFER -------------------------------------------------------------------------------- /Codechef/Factors Finding/README.md: -------------------------------------------------------------------------------- 1 | ## Factors Finding | Problem Code: DIFACTRS 2 | Problems: [https://www.codechef.com/CCSTART2/problems/DIFACTRS](https://www.codechef.com/CCSTART2/problems/DIFACTRS) 3 | 4 | Level: Beginner -------------------------------------------------------------------------------- /Codechef/Find the direction/readme.md: -------------------------------------------------------------------------------- 1 | # PROBLEM LINK 2 | 3 | https://www.codechef.com/START11C/problems/FACEDIR/ 4 | 5 | Level: beginner -------------------------------------------------------------------------------- /Codechef/Fix number of fix points/readme.md: -------------------------------------------------------------------------------- 1 | #PROBLEM LINK 2 | 3 | https://www.codechef.com/START14C/problems/FIXFIX 4 | 5 | #LEVEL : EASY 6 | -------------------------------------------------------------------------------- /Codechef/GCD and LCM/readme.md: -------------------------------------------------------------------------------- 1 | LINK TO THE PROBLEM: 2 | https://www.codechef.com/problems/FLOW016 -------------------------------------------------------------------------------- /Codechef/Golf/readme.md: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/MAY21C/problems/LKDNGOLF/ -------------------------------------------------------------------------------- /Codechef/Golf/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | //Taking number of test cases. 6 | int testcases; 7 | cin>>testcases; 8 | while(testcases--) 9 | { 10 | //Taking the values for N, x, k for each test case. 11 | int N,x,k; 12 | cin>>N>>x>>k; 13 | //Checking if ball will fall into x in lengths of k being shot either from first tile or last. 14 | //if location is x in forward journey, then it becomes N+1-x in the backward journey. 15 | if(x%k==0 or (N+1-x)%k==0) 16 | cout<<"YES\n"; 17 | else 18 | cout<<"NO\n"; 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Codechef/Greedy Puppy/readme.md: -------------------------------------------------------------------------------- 1 | LINK TO THE PROBLEM: 2 | https://www.codechef.com/problems/GDOG -------------------------------------------------------------------------------- /Codechef/Greedy Puppy/solution.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Greedy Puppy solution in c++ 3 | Author : Keshav Prajapati 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | int t, n, k, cal; 12 | cin >> t; 13 | for (int i = 0; i < t; i++) //testCases 14 | { 15 | int coin = 0; 16 | cin >> n >> k; //n=no. of coins,k=no. of peoples 17 | for (int j = 1; j < k + 1; j++) 18 | { 19 | cal = n % j;//checking from 1 to k max no. of coins tuzik can get. 20 | if (cal > coin) 21 | coin = cal;//replacing prev. value if we get more coins. 22 | } 23 | cout << coin << endl; 24 | } 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Codechef/Highest Divisor/readme.md: -------------------------------------------------------------------------------- 1 | # PROBLEM LINK 2 | https://www.codechef.com/FEB21C/problems/HDIVISR/ 3 | 4 | LEVEL : beginner -------------------------------------------------------------------------------- /Codechef/Highest Divisor/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n,md; 6 | cin>>n; //taking input of the number to be checked 7 | for(int i=10;i>=1;i--) //checking for maximum divisor within 10 as per question 8 | { 9 | if(n%i==0){ //when we get the maximum divisor we store it in md then break to come out of the loop 10 | md=i; 11 | break; 12 | } 13 | } 14 | cout<=10 and total_km<21): 12 | prize.append(A) 13 | #condition 3 14 | if(total_km>=21 and total_km<42): 15 | prize.append(A) 16 | prize.append(B) 17 | #condition 4 18 | if(total_km>=42): 19 | prize.append(A) 20 | prize.append(B) 21 | prize.append(C) 22 | 23 | #output is maximum 24 | print(max(prize)) 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Codechef/Maximise the Subsequence Sum/readme.md: -------------------------------------------------------------------------------- 1 | Problem link https://www.codechef.com/problems/SIGNFLIP -------------------------------------------------------------------------------- /Codechef/Maximum Array Xor/readme.md: -------------------------------------------------------------------------------- 1 | LINK TO THE PROBLEM: 2 | 3 | https://www.codechef.com/problems/MAXARXOR -------------------------------------------------------------------------------- /Codechef/Maximum Weight Difference/readme.md: -------------------------------------------------------------------------------- 1 | ## PROBLEM LINK 2 | 3 | https://www.codechef.com/problems/MAXDIFF 4 | 5 | Level: Easy -------------------------------------------------------------------------------- /Codechef/Minimize the digit Sum/readme.md: -------------------------------------------------------------------------------- 1 | #PROBLEM LINK 2 | 3 | https://www.codechef.com/SEPT21B/problems/MNDIGSUM/ -------------------------------------------------------------------------------- /Codechef/Mod Equality/readme.md: -------------------------------------------------------------------------------- 1 | Link: https://www.codechef.com/COOK131C/problems/MODEQUAL 2 | 3 | Language used: C++ 4 | -------------------------------------------------------------------------------- /Codechef/No Time To Wait/readme.md: -------------------------------------------------------------------------------- 1 | # PROBLEM LINK 2 | 3 | https://www.codechef.com/MARCH21C/problems/NOTIME/ 4 | 5 | Level: Beginners -------------------------------------------------------------------------------- /Codechef/Odd gcd/readme.md: -------------------------------------------------------------------------------- 1 | # PROBLEMLINK 2 | 3 | https://www.codechef.com/START14C/problems/BININVER 4 | 5 | Level: Unavailable -------------------------------------------------------------------------------- /Codechef/Olympics Ranking/readme.md: -------------------------------------------------------------------------------- 1 | ## PROBLEM LINK FOR OLYMPICS RANKING 2 | 3 | https://www.codechef.com/AUG21C/problems/OLYRANK -------------------------------------------------------------------------------- /Codechef/Prefix Sums/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://www.codechef.com/LTIME100C/problems/UNQEQ -------------------------------------------------------------------------------- /Codechef/Problem Difficulties/readme.md: -------------------------------------------------------------------------------- 1 | ## PROBLEM LINK FOR PROBLEM DIFFICULTIES 2 | 3 | https://www.codechef.com/AUG21C/problems/PROBDIFF -------------------------------------------------------------------------------- /Codechef/RCB and Playoffs/readme.md: -------------------------------------------------------------------------------- 1 | # PROBLEMLINK 2 | 3 | https://www.codechef.com/START14A/problems/RCBPLAY 4 | 5 | Level: Beginner -------------------------------------------------------------------------------- /Codechef/RCB and Playoffs/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin >> t; //taking input of number of test cases. 8 | while (t--) //running the loop t number of times. 9 | { 10 | int x, y, z; 11 | cin >> x >> y >> z; //taking the input of x(number of present points),y(number of points to qualify) and z(number of matches left) 12 | if (z * 2 + x >= y) //checking if the maximum points that rcb can earn is greater than qualifying point. 13 | cout << "YES" << endl; //printing "YES " if condition statisfied. 14 | else 15 | cout << "NO" << endl; //printing "NO" if condition not statisfied. 16 | } 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Codechef/Remove One Element/readme.md: -------------------------------------------------------------------------------- 1 | # PROBLEM LINK 2 | 3 | https://www.codechef.com/START10C/problems/REMONE 4 | 5 | Level: Beginner -------------------------------------------------------------------------------- /Codechef/Reverse a Number/readme.md: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/problems/FLOW007 -------------------------------------------------------------------------------- /Codechef/Shoe Fit/readme.md: -------------------------------------------------------------------------------- 1 | ## PROBLEM LINK FOR SHOE FIT 2 | 3 | https://www.codechef.com/COOK131C/problems/SHOEFIT -------------------------------------------------------------------------------- /Codechef/Shortest route/readme.md: -------------------------------------------------------------------------------- 1 | Problem link: https://www.codechef.com/JUNE21C/problems/SHROUTE/ 2 | Must try this question!! 3 | -------------------------------------------------------------------------------- /Codechef/Small Factorial/readme.md: -------------------------------------------------------------------------------- 1 | Link: https://www.codechef.com/problems/FLOW018 -------------------------------------------------------------------------------- /Codechef/Smallest Pair/readme.md: -------------------------------------------------------------------------------- 1 | Link: https://www.codechef.com/problems/SMPAIR -------------------------------------------------------------------------------- /Codechef/Smallest Pair/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() { 6 | long long int t,n,a[1000000],small=INT_MAX,i,small2=INT_MAX; 7 | cin>>t; //input no of test cases 8 | while(t--) 9 | { 10 | //input array size 11 | cin>>n; 12 | for(i=0;i>a[i]; 14 | 15 | } 16 | //sorting the array 17 | sort(a,a+n); 18 | //the top 2 elemetns will be smallest and hence their sum will be also the smallest 19 | cout< 6 | using namespace std; 7 | 8 | int main() { 9 | int t; 10 | cin>>t; 11 | for(int i=0;i>q>>p; 15 | if(q<=1000) 16 | cout< length of string 4 | # A => Inter-district time 5 | # B => Inter-state time 6 | s=input() 7 | time=0 8 | 9 | #for every element in s 10 | for i in s: 11 | #if i is 1 then inter-state time added 12 | if(i=="1"): 13 | time+=B 14 | #if i is 0 then inter-district time added 15 | if(i=="0"): 16 | time+=A 17 | #output 18 | print(time) 19 | -------------------------------------------------------------------------------- /Codechef/Two Dishes/readme.md: -------------------------------------------------------------------------------- 1 | # PROBLEM LINK 2 | 3 | https://www.codechef.com/problems/TWODISH/ 4 | 5 | Level :Beginner -------------------------------------------------------------------------------- /Codechef/Vaccine Dates/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://www.codechef.com/LTIME100C/problems/VDATES -------------------------------------------------------------------------------- /Codechef/Vaccine Dates/solution.cpp: -------------------------------------------------------------------------------- 1 | //Find if Chef is on time to take his 2nd dose of vaccine 2 | //It has been 'd' days since Chef took his 1st dose 3 | //Chef should take his 2nd dose no less than 'l' days after 1st dose 4 | //Chef should take his 2nd does no more than 'r' days after 1st does 5 | 6 | #include 7 | using namespace std; 8 | 9 | int main() { 10 | int t; 11 | cin>>t; //Variable for test cases 12 | while(t--) 13 | { 14 | int d,l,r; 15 | cin>>d>>l>>r; 16 | if(dr) //Case where Chef is too late 19 | cout<<"Too Late\n"; 20 | else //Case where Chef is on time 21 | cout<<"Take second dose now\n"; 22 | 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Codechef/Which_Mixture/README.md: -------------------------------------------------------------------------------- 1 | https://www.codechef.com/OCT21C/problems/MIXTURE -------------------------------------------------------------------------------- /Codechef/longest and subarray/readme.md: -------------------------------------------------------------------------------- 1 | link: https://www.codechef.com/OCT21C/problems/ANDSUBAR -------------------------------------------------------------------------------- /Codechef/three boxes/readme.md: -------------------------------------------------------------------------------- 1 | link: https://www.codechef.com/OCT21C/problems/THREEBOX -------------------------------------------------------------------------------- /Codeforces/ Productive Meeting/readme.md: -------------------------------------------------------------------------------- 1 | # PRODUCTIVE MEETING 2 | 3 | ## Codeforces Round #744 (Div. 3) 4 | 5 | ## problem link : https://codeforces.com/contest/1579/problem/D 6 | -------------------------------------------------------------------------------- /Codeforces/A-Puzzles/readme.md: -------------------------------------------------------------------------------- 1 | Problem link https://codeforces.com/contest/337/problem/A -------------------------------------------------------------------------------- /Codeforces/A-Puzzles/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long ll; 4 | int main(){ 5 | ios::sync_with_stdio(0); 6 | cin.tie(0); 7 | ll n,m; // n is number of students. m is number of puzzles in shop 8 | cin>>n>>m; 9 | ll puzzle[m]; //array for puzzles 10 | for(ll i=0;i>puzzle[i]; 11 | sort(puzzle,puzzle+m); 12 | ll start =0,end=n-1; 13 | ll diff=0,minDiff = INT_MAX; // diff is for storing difference in every iteration and minDiff is the minimum difference among them which is also the output 14 | while(end 2 | #define int long long 3 | using namespace std; 4 | int32_t main(){ 5 | int n; 6 | cin>>n; 7 | int ar[n]; 8 | for(int i=0;i>ar[i]; //to input the programming skill of the ith student 10 | } 11 | sort(ar,ar+n); //sorting the array of programming skills in ascending order 12 | int ans=0; //to store the maximum possible number of students in balanced team 13 | int j=0; 14 | for (int i=0;i 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int i,j,n=0; 9 | for(i=1;i<=5;i++) //loop to start with row 10 | { 11 | for(j=1;j<=5;j++) //loop to start with column 12 | { 13 | cin>>n; //storing value of each cell 14 | if(n==1) //searching for 1 in a cell 15 | { 16 | cout< 2 | using namespace std; 3 | #define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //speeds up the code execution 4 | /* 5 | We examine two cases: 6 | a=b — the segment consists of a single number, hence the answer is a. 7 | a>a>>b; 14 | if(a==b) 15 | { 16 | cout< 0: 20 | 21 | # Adding one member to stack and if the current stack able to form a team then increment val 22 | v.append(a.pop()) 23 | if v[-1] * len(v) >= x: 24 | v = [] 25 | val += 1 26 | 27 | print(val) -------------------------------------------------------------------------------- /Codeforces/Customising the Track/readme.md: -------------------------------------------------------------------------------- 1 | ## Customising the Track 2 | - question link: https://codeforces.com/contest/1543/problem/B 3 | -------------------------------------------------------------------------------- /Codeforces/Diameter of Graph/readme.md: -------------------------------------------------------------------------------- 1 | # Diameter of graph 2 | 3 | ## problem link : (Diameter of graph)[https://codeforces.com/contest/1581/problem/B] 4 | 5 | ## rated 1200 -------------------------------------------------------------------------------- /Codeforces/Dice Tower/readme.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/Die Roll/Die Roll.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | int a,b; 8 | cin>>a>>b;// take input of max amount of both or if same any one of their die value 9 | int m=max(a,b); 10 | int r=6-m+1; // to get 1 more or equal she has 6 - max +1 ways to win 11 | // if she needs 5 or more she has 5,6 output needed which is number of ways == 6-5+1 =2 12 | 13 | int z=__gcd(r,6); // to print in lowest fraction we take gcd 14 | cout< 0: 16 | s += val % 10 17 | val = val // 10 18 | 19 | # Use gcd function. If condition is satisfied output the number and break the loop. 20 | if math.gcd(n, s) > 1: 21 | print(n) 22 | break 23 | n += 1 -------------------------------------------------------------------------------- /Codeforces/GameWithArray/README.md: -------------------------------------------------------------------------------- 1 | # GameWithArray 2 | 3 | ## Codeforces Round #643 (Div. 2) 4 | 5 | ## problem link : https://codeforces.com/contest/1355/problem/D 6 | -------------------------------------------------------------------------------- /Codeforces/Inconvinient Pairs/readme.md: -------------------------------------------------------------------------------- 1 | problem link: https://codeforces.com/contest/1569/problem/D 2 | -------------------------------------------------------------------------------- /Codeforces/Infinity Table/README.md: -------------------------------------------------------------------------------- 1 | # Infinity Table 2 | 3 | ## Codeforces Round #739 (Div. 3) 4 | 5 | **Problem Link: https://codeforces.com/contest/1560/problem/C** 6 | 7 | -------------------------------------------------------------------------------- /Codeforces/Is your horseshoe on the other hoof/readme.md: -------------------------------------------------------------------------------- 1 | # Is your horseshoe on the other hoof? 2 | 3 | ### link 4 | https://codeforces.com/problemset/problem/228/A -------------------------------------------------------------------------------- /Codeforces/Is your horseshoe on the other hoof/solution.cpp: -------------------------------------------------------------------------------- 1 | //228A - Is your horseshoe on the other hoof? 2 | // Code by :- Rishav Singh Solanki 3 | 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | int arr[5], e = 3; 9 | int main() { 10 | for (int i = 0; i < 4; i++) { 11 | cin >> arr[i]; //Taking input from users 12 | } 13 | sort(arr, arr + 4); // Sorting the array 14 | for (int i = 0; i < 3; i++) { 15 | if (arr[i] != arr[i + 1]) { //Checking for same numbers 16 | e--; 17 | } 18 | } 19 | cout << e; 20 | } -------------------------------------------------------------------------------- /Codeforces/K Divisible Sum/readme.md: -------------------------------------------------------------------------------- 1 | # Diameter of graph 2 | 3 | ## problem link : (K Divisible Sum)[https://codeforces.com/problemset/problem/1476/A] 4 | 5 | ## rated 1000 -------------------------------------------------------------------------------- /Codeforces/Kayaking/readme.md: -------------------------------------------------------------------------------- 1 | # Contest: 2 | ### Educational Codeforces Round 29 3 | ## Problem Link: 4 | https://codeforces.com/contest/863/problem/B -------------------------------------------------------------------------------- /Codeforces/Lucky Mask/README.md: -------------------------------------------------------------------------------- 1 | # Lucky Mask 2 | 3 | ## Codeforces Round #104 (Div. 2) 4 | 5 | ## problem link : https://codeforces.com/contest/146/problem/B -------------------------------------------------------------------------------- /Codeforces/Lucky Mask/solution.py: -------------------------------------------------------------------------------- 1 | # Function to calculate the mask of a number. 2 | def split(n): 3 | b = [] 4 | # Iterating the number by digits. 5 | while n > 0: 6 | # If the digit is lucky digit it is appended to the list. 7 | if n % 10 == 4 or n % 10 == 7: 8 | b.append(n % 10) 9 | n //= 10 10 | # Return the mask. 11 | return b 12 | 13 | 14 | # Input the two input values. 15 | x, y = [int(x) for x in input().split()] 16 | # Calculate the mask of 'y'. 17 | a = split(y) 18 | # Iterate for value greater than 'x'. 19 | for i in range(x + 1, 1000000): 20 | # If mask equals output the integer and break the loop. 21 | if split(i) == a: 22 | print(i) 23 | break -------------------------------------------------------------------------------- /Codeforces/LuxiriousHouse/readme.md: -------------------------------------------------------------------------------- 1 | problem link -https://codeforces.com/contest/581/problem/B 2 | -------------------------------------------------------------------------------- /Codeforces/MAX-MEX Cut/Readme.md: -------------------------------------------------------------------------------- 1 | Codeforces Global Round 16 | Problem C. MAX-MEX Cut 2 | Problem Link : https://codeforces.com/contest/1566/problem/C 3 | 4 | -------------------------------------------------------------------------------- /Codeforces/MIN-MEX Cut/readme.md: -------------------------------------------------------------------------------- 1 | Codeforces Global Round 16 | Problem B. MIN-MEX Cut 2 | Problem Link : https://codeforces.com/contest/1566/problem/B -------------------------------------------------------------------------------- /Codeforces/Median Maximization/readme.md: -------------------------------------------------------------------------------- 1 | # Contest: 2 | 3 | ### Codeforces Global Round 16 4 | 5 | ## Problem Link: 6 | 7 | https://codeforces.com/contest/1566/problem/A 8 | -------------------------------------------------------------------------------- /Codeforces/Mocha and Hiking/README.md: -------------------------------------------------------------------------------- 1 | "Mocha and Hiking" 2 | 3 | #Codeforces Contest : Codeforces Round #738 (Div. 2) 4 | 5 | #Problem Link : https://codeforces.com/contest/1559/problem/C -------------------------------------------------------------------------------- /Codeforces/Multiply by two divide by six/ README.md: -------------------------------------------------------------------------------- 1 | Link : https://codeforces.com/contest/1374/problem/B 2 | -------------------------------------------------------------------------------- /Codeforces/National Project/readme.md: -------------------------------------------------------------------------------- 1 | # National Project 2 | ## Educational Codeforces Round 82 (Rated for Div. 2) 3 | ## Problem Link : https://codeforces.com/contest/1303/problem/B -------------------------------------------------------------------------------- /Codeforces/Nearly Lucky Number/README.md: -------------------------------------------------------------------------------- 1 | # Nearly Lucky Number 2 | 3 | ## Codeforces Beta Round #84 (Div. 2 Only) 4 | 5 | **Problem Link: https://codeforces.com/problemset/problem/110/A** 6 | 7 | -------------------------------------------------------------------------------- /Codeforces/Nearly Lucky Number/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | long long int n; 5 | long long int count=0; 6 | 7 | cin >> n; // input the number 8 | while(n!=0){ 9 | if (n%10==4 || n%10 ==7){ //check if the number is 4 or 7 10 | count++; // increment the count of lucky numbers 11 | } 12 | n/=10; //remove the right most digit from the number 13 | } 14 | // check if the count is a lucky number 15 | if (count==4 || count==7) 16 | cout << "YES"; 17 | else 18 | cout << "NO"; 19 | 20 | } -------------------------------------------------------------------------------- /Codeforces/Non-zero/readme.md: -------------------------------------------------------------------------------- 1 | Problem link: https://codeforces.com/contest/1300/problem/A 2 | -------------------------------------------------------------------------------- /Codeforces/Permutation Minimization by Deque/readme.md: -------------------------------------------------------------------------------- 1 | # Contest: 2 | ### Codeforces Round #744 (Div. 3) 3 | ## Problem Link: 4 | https://codeforces.com/problemset/problem/1579/E1 -------------------------------------------------------------------------------- /Codeforces/Queue at the School/readme.md: -------------------------------------------------------------------------------- 1 | http://codeforces.com/problemset/problem/266/B 2 | -------------------------------------------------------------------------------- /Codeforces/Regular Bracket Sequences/readme.md: -------------------------------------------------------------------------------- 1 | # Regular Bracket Sequences 2 | 3 | ## Educational Codeforces Round 114 (Rated for Div. 2) 4 | 5 | ## https://codeforces.com/contest/1574/problem/A 6 | -------------------------------------------------------------------------------- /Codeforces/Scenes From a Memory/readme.md: -------------------------------------------------------------------------------- 1 | # Scenes From a Memory 2 | 3 | ## Codeforces Round #741 (Div. 2) 4 | 5 | **Problem Link: https://codeforces.com/contest/1562/problem/B** 6 | -------------------------------------------------------------------------------- /Codeforces/Seating Arrangements hard version/readme.md: -------------------------------------------------------------------------------- 1 | problem link: https://codeforces.com/contest/1566/problem/D2 -------------------------------------------------------------------------------- /Codeforces/Semifinals/readme.md: -------------------------------------------------------------------------------- 1 | # Semifinals 2 | 3 | ## Codeforces Round #222 (Div. 2) 4 | 5 | ## problem link : https://codeforces.com/contest/378/problem/B 6 | -------------------------------------------------------------------------------- /Codeforces/Spreadsheets/readme.md: -------------------------------------------------------------------------------- 1 | # Spreadsheets 2 | 3 | ## Codeforces Beta Round #1 4 | 5 | ## Problem Link: https://codeforces.com/contest/1/problem/B 6 | -------------------------------------------------------------------------------- /Codeforces/T-Primes/Readme.md: -------------------------------------------------------------------------------- 1 | # T-primes 2 | 3 | ## Codeforces Round #142 (Div. 2) 4 | 5 | **Problem Link: https://codeforces.com/problemset/problem/230/B** 6 | 7 | -------------------------------------------------------------------------------- /Codeforces/The Miracle and the Sleeper/readme.md: -------------------------------------------------------------------------------- 1 | # A. The Miracle and the Sleeper 2 | 3 | ## Codeforces Round #741 (Div. 2) 4 | 5 | ## https://codeforces.com/contest/1562/problem/A 6 | 7 | -------------------------------------------------------------------------------- /Codeforces/Train-Maintenance/readme.md: -------------------------------------------------------------------------------- 1 | # Train Maintenance 2 | 3 | ## Codeforces Round #745 (Div. 2) 4 | 5 | ## https://codeforces.com/contest/1581/problem/E -------------------------------------------------------------------------------- /Codeforces/Tram/readme.md: -------------------------------------------------------------------------------- 1 | ## Tram question link 2 | 3 | - Problem link: [https://codeforces.com/problemset/problem/116/A](https://codeforces.com/problemset/problem/116/A) 4 | -------------------------------------------------------------------------------- /Codeforces/Tricks/readme.md: -------------------------------------------------------------------------------- 1 | # Tricks 2 | 3 | ## Codeforces Round #744 (Div. 3) 4 | 5 | ## https://codeforces.com/contest/1579/problem/C 6 | -------------------------------------------------------------------------------- /Codeforces/Two Platforms/readme.md: -------------------------------------------------------------------------------- 1 | # Two Platforms 2 | 3 | ## Contest: Codeforces Round 667 (Div. 3) 4 | 5 | ## problem link: https://codeforces.com/contest/1409/problem/E 6 | -------------------------------------------------------------------------------- /Codeforces/Two Round Dances/readme.md: -------------------------------------------------------------------------------- 1 | # Contest: 2 | ### Codeforces Round #677 (Div. 3) 3 | ## Problem Link: 4 | https://codeforces.com/contest/1433/problem/E -------------------------------------------------------------------------------- /Codeforces/Two Round Dances/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | #define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //speeds up the code 5 | /* 6 | prerequisite - circular permutations 7 | learn from here: https://www.tutorialspoint.com/statistics/circular_permutation 8 | */ 9 | int factorial(int n) 10 | { 11 | int ans = 1; 12 | for(int i = 1; i <= n; ++i) { 13 | ans *= i; 14 | } 15 | return ans; 16 | }; 17 | signed main(){ 18 | FIO 19 | int n; 20 | cin>>n; 21 | int ans = factorial(n)/((n/2)*(n/2)*2); //calculated using circular permutations.. We devided by 2 to prevent counting ordered pairs 22 | cout < 2 | using namespace std; 3 | void solve(){ 4 | /*if string size is greater than 10, we will print first character, 5 | then (length of string -2) which is the remaining characters in between the first and 6 | last element of the string, and then we print the last character of the string..otherwise if length is 7 | less than or equal to 10,then we simply print the string*/ 8 | string s; 9 | cin>>s; 10 | int l=s.size(); 11 | if(l>10) cout<>t; 19 | while(t--){ 20 | solve(); 21 | }} 22 | -------------------------------------------------------------------------------- /Codeforces/Wizard of Orz/readme.md: -------------------------------------------------------------------------------- 1 | # Codeforces Problem: 2 | - Wizard of Orz - 1467A 3 | # Problem Link: 4 | - https://codeforces.com/contest/1467/problem/A -------------------------------------------------------------------------------- /Codeforces/Yet Another Card Deck/readme.md: -------------------------------------------------------------------------------- 1 | # Yet Another Card Deck 2 | 3 | ## Educational Codeforces Round 107 (Rated for Div. 2) 4 | 5 | ## Problem Link : https://codeforces.com/contest/1511/problem/C 6 | 7 | 8 | -------------------------------------------------------------------------------- /Codeforces/Young Photographer/readme.md: -------------------------------------------------------------------------------- 1 | # Young Photographer 2 | 3 | ## Codeforces Beta Round #14 (Div. 2) 4 | 5 | ## Problem Link : https://codeforces.com/contest/14/problem/B 6 | 7 | 8 | -------------------------------------------------------------------------------- /Codeforces/Young Physicist/readme.md: -------------------------------------------------------------------------------- 1 | https://codeforces.com/problemset/problem/69/A 2 | -------------------------------------------------------------------------------- /Codeforces/cupboards/readme.md: -------------------------------------------------------------------------------- 1 | ## Cupboards question link 2 | 3 | - Problem link: [https://codeforces.com/problemset/problem/248/A](https://codeforces.com/problemset/problem/248/A) 4 | -------------------------------------------------------------------------------- /GeeksForGeeks/Check for BST/readme.md: -------------------------------------------------------------------------------- 1 | https://practice.geeksforgeeks.org/problems/check-for-bst/1/?company[]=Amazon&company[]=Amazon&problemType=functional&page=1&sortBy=submissions&query=company[]AmazonproblemTypefunctionalpage1sortBysubmissionscompany[]Amazon 2 | -------------------------------------------------------------------------------- /GeeksForGeeks/Check if the door is open or closed/readme.md: -------------------------------------------------------------------------------- 1 | Link to the problem: 2 | [Check if the door is open or closed](https://practice.geeksforgeeks.org/problems/check-if-the-door-is-open-or-closed2013/1/?company[]=TCS&company[]=TCS&page=1&query=company[]TCSpage1company[]TCS#) -------------------------------------------------------------------------------- /GeeksForGeeks/Check whether two strings are anagram of each other/readme.md: -------------------------------------------------------------------------------- 1 | https://www.geeksforgeeks.org/check-whether-two-strings-are-anagram-of-each-other/ 2 | 3 | Tag : Easy -------------------------------------------------------------------------------- /GeeksForGeeks/Chocolate Distribution Problem/readme.md: -------------------------------------------------------------------------------- 1 | https://practice.geeksforgeeks.org/problems/chocolate-distribution-problem3825/1 2 | 3 | Tag: Easy 4 | -------------------------------------------------------------------------------- /GeeksForGeeks/Convert Binary Tree to BST/Readme.md: -------------------------------------------------------------------------------- 1 | https://practice.geeksforgeeks.org/problems/binary-tree-to-bst/1 2 | 3 | Tag: Easy -------------------------------------------------------------------------------- /GeeksForGeeks/Count-triplets-sorted-doubly-linked-list-whose-sum-equal-given-value-x/Readme.md: -------------------------------------------------------------------------------- 1 | # Move the Last Node to First 2 | 3 | ## Question Link :- https://www.geeksforgeeks.org/count-triplets-sorted-doubly-linked-list-whose-sum-equal-given-value-x/ -------------------------------------------------------------------------------- /GeeksForGeeks/Detect Loop in linked list/Readme.md: -------------------------------------------------------------------------------- 1 | # Detect Loop in linked list 2 | ## Question Link :- https://practice.geeksforgeeks.org/problems/detect-loop-in-linked-list/1 -------------------------------------------------------------------------------- /GeeksForGeeks/Detect cycle in an undirected graph/readme.md: -------------------------------------------------------------------------------- 1 | Given an Undirected Graph, determine a cycle present in the graph or not. 2 | 3 | Link: https://practice.geeksforgeeks.org/problems/detect-cycle-in-an-undirected-graph/1 4 | 5 | Tag : Medium 6 | -------------------------------------------------------------------------------- /GeeksForGeeks/Detect cycle in undirected graph/readme.md: -------------------------------------------------------------------------------- 1 | ## Detect cycle in an undirected graph 2 | ### Problem statement 3 | Given an undirected graph with V vertices and E edges, check whether it contains any cycle or not. 4 | 5 | **Link** : https://practice.geeksforgeeks.org/problems/detect-cycle-in-an-undirected-graph/1# 6 | 7 | Tag : **Medium** 8 | 9 | -------------------------------------------------------------------------------- /GeeksForGeeks/Given a linked list of 0s, 1s and 2s, sort it/Readme.md: -------------------------------------------------------------------------------- 1 | # Given_ll_of_0_1_2_sort 2 | 3 | ## Question Link :- https://practice.geeksforgeeks.org/problems/given-a-linked-list-of-0s-1s-and-2s-sort-it/1 -------------------------------------------------------------------------------- /GeeksForGeeks/Goldmine Problem/README.md: -------------------------------------------------------------------------------- 1 | ## Gold Mine Problem 2 | Problems: [https://practice.geeksforgeeks.org/problems/gold-mine-problem2608/1](https://practice.geeksforgeeks.org/problems/gold-mine-problem2608/1) 3 | 4 | Level: Easy -------------------------------------------------------------------------------- /GeeksForGeeks/Intersection Point in Y Shapped ll/readme.md: -------------------------------------------------------------------------------- 1 | # Intersection Point In Y Shapped LinkedList 2 | 3 | ## Question Link:- https://practice.geeksforgeeks.org/problems/intersection-point-in-y-shapped-linked-lists/1 4 | -------------------------------------------------------------------------------- /GeeksForGeeks/Intersection of arrays/README.md: -------------------------------------------------------------------------------- 1 | Given two arrays a[] and b[] respectively of size n and m, the task is to print the count of elements in the intersection (or common elements) of the two arrays. 2 | 3 | For this question, the intersection of two arrays can be defined as the set containing distinct common elements between the two arrays. 4 | 5 | Link: 6 | https://practice.geeksforgeeks.org/problems/intersection-of-two-arrays2404/1 7 | 8 | Tag : Easy 9 | -------------------------------------------------------------------------------- /GeeksForGeeks/Kadanes Algorithm/readme.md: -------------------------------------------------------------------------------- 1 | ## Kadane's Algorithm 2 | # Problem Statement 3 | Given an array Arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the maximum sum and return its sum. 4 | 5 | 6 | **Link** https://practice.geeksforgeeks.org/problems/kadanes-algorithm-1587115620/1 7 | -------------------------------------------------------------------------------- /GeeksForGeeks/Kadanes Algorithm/solution.java: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | 3 | // arr: input array 4 | // n: size of array 5 | //Function to find the sum of contiguous subarray with maximum sum. 6 | 7 | int maxSubarraySum(int arr[], int n){ 8 | 9 | //initializing the max value with minimum int value 10 | int max= Integer.MIN_VALUE; 11 | int positiveSum= 0; 12 | 13 | //checking and updating the max and positiveSum values 14 | for(int i=0; i sieveOfEratosthenes(int N) 2 | { 3 | vector prime(N+1,1); 4 | //create a vector to store all numbers upto n (n+1 because vectors are zero indexed) 5 | vectorans; 6 | for(int i=2;i<=N;i++) 7 | { 8 | if(prime[i]==1) //check if the current number is prime 9 | { 10 | for(int j = 2*i;j<=N;j+=i) 11 | { 12 | prime[j]=0;//make all multiples of the current num to 0 13 | } 14 | ans.push_back(i); //insert that number 15 | } 16 | } 17 | return ans; 18 | } -------------------------------------------------------------------------------- /GeeksForGeeks/Sieve of Erastosthenes/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://practice.geeksforgeeks.org/problems/sieve-of-eratosthenes5242/1 2 | 3 | Given a number N, calculate the prime numbers up to N using Sieve of Eratosthenes. -------------------------------------------------------------------------------- /GeeksForGeeks/Sort accoridng to frequency/readme.md: -------------------------------------------------------------------------------- 1 | 2 | Problem link :- https://practice.geeksforgeeks.org/problems/sorting-elements-of-an-array-by-frequency/0# 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /GeeksForGeeks/Sort an array of 0s 1s and 2s/readme.md: -------------------------------------------------------------------------------- 1 | 2 | Problem link :- https://practice.geeksforgeeks.org/problems/sort-an-array-of-0s-1s-and-2s4231/1 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Hackerearth/Alice and candies/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-1/practice-problems/algorithm/lola-and-candies-36b57b1b/ -------------------------------------------------------------------------------- /Hackerearth/Balancing cubes/readme.md: -------------------------------------------------------------------------------- 1 | problem link : https://www.hackerearth.com/problem/algorithm/balance-it-2-dc8872e2/ -------------------------------------------------------------------------------- /Hackerearth/Counting Frog Paths/readme.md: -------------------------------------------------------------------------------- 1 | # Counting Frog Paths 2 | ## Link to problem 3 | 4 | https://www.hackerearth.com/practice/algorithms/searching/linear-search/practice-problems/algorithm/counting-frog-paths-1abd84d5/ -------------------------------------------------------------------------------- /Hackerearth/Likeable arrays/readme.md: -------------------------------------------------------------------------------- 1 |

Likeable arrays

2 | Link: https://www.hackerearth.com/practice/algorithms/greedy/basics-of-greedy-algorithms/practice-problems/algorithm/likeable-array-3e61d786/ 3 | -------------------------------------------------------------------------------- /Hackerearth/Lunchboxes/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.hackerearth.com/practice/basic-programming/implementation/basics-of-implementation/practice-problems/algorithm/lunch-boxes-019bf2a5/submissions/ -------------------------------------------------------------------------------- /Hackerearth/Maximum Sum/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.hackerearth.com/practice/algorithms/searching/linear-search/practice-problems/algorithm/maximum-sum-4-f8d12458/submissions/ -------------------------------------------------------------------------------- /Hackerearth/Minimum Length/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.hackerearth.com/practice/algorithms/string-algorithm/string-searching/practice-problems/algorithm/minimum-length-2-d2b8af58/ -------------------------------------------------------------------------------- /Hackerearth/Non-decreasing arrays/READme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerearth.com/practice/data-structures/arrays/1-d/practice-problems/algorithm/make-it-non-decreasing-7d3391fd/ -------------------------------------------------------------------------------- /Hackerearth/Pizza Confusion/readme.md: -------------------------------------------------------------------------------- 1 |

Pizza Confusion

2 | Link: https://www.hackerearth.com/practice/algorithms/sorting/bubble-sort/practice-problems/algorithm/pizza-confusion/description/ 3 | -------------------------------------------------------------------------------- /Hackerearth/The Best Player/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.hackerearth.com/practice/algorithms/sorting/bubble-sort/practice-problems/algorithm/the-best-player-1/ -------------------------------------------------------------------------------- /Hackerearth/Zero subarray/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.hackerearth.com/practice/algorithms/greedy/basics-of-greedy-algorithms/practice-problems/algorithm/zero-subarray-8358c5d9/ -------------------------------------------------------------------------------- /Hackerrank/3D Surface area/README.md: -------------------------------------------------------------------------------- 1 | Problem Link :- https://www.hackerrank.com/challenges/3d-surface-area/problem?isFullScreen=true -------------------------------------------------------------------------------- /Hackerrank/A Very Big Sum/README.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/a-very-big-sum/problem -------------------------------------------------------------------------------- /Hackerrank/A Very Big Sum/solution2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | // Defining ull : because a sum of 10 integers can overflow integer range, hence we need to store it in a higher datatype 3 | #define ull unsigned long long 4 | using namespace std; 5 | 6 | ull calculateSum(int n){ 7 | ull sum = 0; 8 | int x; 9 | for(int i=0; i>x; 12 | sum += x; 13 | } 14 | return sum; 15 | } 16 | 17 | int main(){ 18 | int n; 19 | // Collecting size of the input array 20 | cin>>n; 21 | // Printing the result 22 | cout< 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 | using namespace std; 7 | 8 | 9 | int main() { 10 | int N, d; // N = array , d = operation we have to perform 11 | cin >> N >> d; //taking input of n and d 12 | vector v(N); // specifing that the vector has a size of N 13 | for (size_t i = 0; i < v.size(); ++i) 14 | { 15 | cin >> v[i]; //taking input 16 | } 17 | d = d % N; 18 | for (int i = d; i < N; ++i) 19 | cout << v[i] << ' '; // printing the array output 20 | for (int i = 0; i < d; ++i) // for loop 21 | cout << v[i] << ' '; // printing the array output 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Hackerrank/Array Manipulation/README.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/crush/problem -------------------------------------------------------------------------------- /Hackerrank/Array Reversal/README.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/reverse-array-c/problem -------------------------------------------------------------------------------- /Hackerrank/Array Reversal/solution.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | //declaring variables 7 | int num, *arr, i; 8 | //input num 9 | scanf("%d", &num); 10 | //dynamic allocation of arr 11 | arr = (int*) malloc(num * sizeof(int)); 12 | //for loop to scan the array 13 | for(i = 0; i < num; i++) 14 | { 15 | scanf("%d", &arr[i]); 16 | } 17 | // logic to reverse the array 18 | for(i = num-1; i >=0; i--) 19 | printf("%d ", arr[i]); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Hackerrank/Balanced Brackets/readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/balanced-brackets/problem -------------------------------------------------------------------------------- /Hackerrank/Beautiful Pairs/Readme.md: -------------------------------------------------------------------------------- 1 | Problem link:- https://www.hackerrank.com/challenges/beautiful-pairs/problem? -------------------------------------------------------------------------------- /Hackerrank/Beautiful Triplets/README.md: -------------------------------------------------------------------------------- 1 | Problem : https://www.hackerrank.com/challenges/beautiful-triplets/problem -------------------------------------------------------------------------------- /Hackerrank/Bigger is Greater/readme.md: -------------------------------------------------------------------------------- 1 | # PROBLEM LINK 2 | 3 | https://www.hackerrank.com/challenges/bigger-is-greater/problem 4 | 5 | Level : Medium -------------------------------------------------------------------------------- /Hackerrank/Bill Division/Solution.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.List; 3 | public class Solution { 4 | public static void main(String[] args) { 5 | 6 | } 7 | public static void bonAppetit(List bill, int k, int b) { 8 | int actualBill = 0; 9 | for (int i = 0; i < bill.size(); i++) { 10 | if (!(i == k)) { 11 | actualBill += bill.get(i); 12 | } 13 | } 14 | actualBill = actualBill / 2; 15 | if (b == actualBill) { 16 | System.out.println("Bon Appetit"); 17 | } else { 18 | System.out.print(b - actualBill); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Hackerrank/Bill Division/readme.md: -------------------------------------------------------------------------------- 1 | Problem: [https://www.hackerrank.com/challenges/bon-appetit/problem](https://www.hackerrank.com/challenges/bon-appetit/problem) -------------------------------------------------------------------------------- /Hackerrank/Birthday Cake Candles/README.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/birthday-cake-candles/problem -------------------------------------------------------------------------------- /Hackerrank/CPP Variadics/readme.md: -------------------------------------------------------------------------------- 1 | Problem link: https://www.hackerrank.com/challenges/cpp-variadics/problem -------------------------------------------------------------------------------- /Hackerrank/Caesar Cipher/readme.md: -------------------------------------------------------------------------------- 1 | # Caesar Cipher 2 | 3 | #### Link: https://www.hackerrank.com/challenges/caesar-cipher-1/problem -------------------------------------------------------------------------------- /Hackerrank/CamelCase/readme.md: -------------------------------------------------------------------------------- 1 | Problem: [https://www.hackerrank.com/challenges/camelcase/problem](https://www.hackerrank.com/challenges/camelcase/problem) 2 | -------------------------------------------------------------------------------- /Hackerrank/Climbing the Leaderboard/readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Cycle Detection/readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/detect-whether-a-linked-list-contains-a-cycle/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Day of a Programmer/readme.md: -------------------------------------------------------------------------------- 1 | Problem link: https://www.hackerrank.com/challenges/day-of-the-programmer/problem -------------------------------------------------------------------------------- /Hackerrank/Day of the programmer/readme.md: -------------------------------------------------------------------------------- 1 | Problem link: https://www.hackerrank.com/challenges/day-of-the-programmer/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Dequeue STL/readme.md: -------------------------------------------------------------------------------- 1 | Dequeue STL 2 | 3 | https://www.hackerrank.com/challenges/deque-stl/problem -------------------------------------------------------------------------------- /Hackerrank/Designer Door Mat/Readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/designer-door-mat/problem -------------------------------------------------------------------------------- /Hackerrank/Designer PDF Viewer/README.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://www.hackerrank.com/challenges/designer-pdf-viewer/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Diagonal Difference/readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/diagonal-difference/problem -------------------------------------------------------------------------------- /Hackerrank/Diagonal Difference/solution.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | arr = [] 3 | l_sum = 0 4 | r_sum = 0 5 | 6 | # For getting the user input 7 | for i in range(n): 8 | arr.append(list(map(int, input().split()))) 9 | 10 | # For the sum 11 | for i in range(n): 12 | for j in range(n): 13 | # To find the sum of left diagonal 14 | if i == j: 15 | l_sum = l_sum + arr[i][j] 16 | 17 | # To find the sum of right diagonal 18 | if i + j == (n - 1): 19 | r_sum = r_sum + arr[i][j] 20 | 21 | result = abs(l_sum - r_sum) 22 | 23 | print(result) 24 | -------------------------------------------------------------------------------- /Hackerrank/DigitFrequency/readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/frequency-of-digits-1/problem -------------------------------------------------------------------------------- /Hackerrank/Electronics Shop/README.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/electronics-shop/problem -------------------------------------------------------------------------------- /Hackerrank/Encryption/README.md: -------------------------------------------------------------------------------- 1 | Problem link:- https://www.hackerrank.com/challenges/encryption/problem -------------------------------------------------------------------------------- /Hackerrank/Equalize the Array/README.md: -------------------------------------------------------------------------------- 1 | Problem : https://www.hackerrank.com/challenges/equality-in-a-array/problem -------------------------------------------------------------------------------- /Hackerrank/FairRations/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.hackerrank.com/challenges/fair-rations/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Find the Median/README.md: -------------------------------------------------------------------------------- 1 | Problem Link - https://www.hackerrank.com/challenges/find-the-median -------------------------------------------------------------------------------- /Hackerrank/Find the Runner-Up Score/readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list/problem?isFullScreen=false 2 | -------------------------------------------------------------------------------- /Hackerrank/Find the running median/readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/find-the-running-median/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Flatland Space Stations/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link:- https://www.hackerrank.com/challenges/flatland-space-stations/problem -------------------------------------------------------------------------------- /Hackerrank/Flipping bits/README.md: -------------------------------------------------------------------------------- 1 | Problem link - https://www.hackerrank.com/challenges/flipping-bits -------------------------------------------------------------------------------- /Hackerrank/Flipping bits/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long int t; 7 | cin>>t; // Taking input of number of testcases 8 | while(t--){ 9 | long long int n; // Temp variable to store the testcases 10 | cin>>n; 11 | long long int a= 4294967295-n; // Flipping the bits 12 | cout< 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin>>n; 8 | int arr[n]; 9 | // Input the array elements. 10 | for(int i=0; i>arr[i]; 12 | } 13 | int count=0; // counter for counting number of jumps. 14 | for(int i=0; i 1: 17 | lent = len(string)-2 18 | string = string[:lent] + "]" 19 | else: 20 | string += "]" 21 | 22 | #Finally displaying the permutations list 23 | print(string) 24 | -------------------------------------------------------------------------------- /Hackerrank/Mars Exploration/README.md: -------------------------------------------------------------------------------- 1 | Problem Link - https://www.hackerrank.com/challenges/mars-exploration 2 | -------------------------------------------------------------------------------- /Hackerrank/Merge the Tools/README.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://www.hackerrank.com/challenges/merge-the-tools/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Merge the Tools/solution.py: -------------------------------------------------------------------------------- 1 | #Function to return unique characters from passed substrings 2 | def uniq_str(s): 3 | r_str = "" 4 | for char in range(len(s)): 5 | if r_str.count(s[char:char+1]) != 1: 6 | r_str += s[char:char+1] 7 | return r_str 8 | 9 | #Main function that'll be executed 10 | def merge_the_tools(string, k): 11 | st = "" 12 | for i in range(int(len(string)/k)): 13 | s = string[i*k:i*k+k] #Breaking off the main string into multiple substrings of length k 14 | st += uniq_str(s) + "\n" #Cumulative addition of output for each substring 15 | i = len(st) 16 | print(st[0:i-1]) 17 | return 0 18 | 19 | -------------------------------------------------------------------------------- /Hackerrank/Messages Order/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.hackerrank.com/challenges/messages-order/problem -------------------------------------------------------------------------------- /Hackerrank/Migratory Birds/README.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/migratory-birds/problem -------------------------------------------------------------------------------- /Hackerrank/Mini-Max Sum/readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/mini-max-sum/problem -------------------------------------------------------------------------------- /Hackerrank/Minimum Distances/Readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/minimum-distances/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Multi Level Inheritance/README.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/multi-level-inheritance-cpp/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/New Companies/Readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/the-company/problem -------------------------------------------------------------------------------- /Hackerrank/New Companies/Solution.sql: -------------------------------------------------------------------------------- 1 | /* Since we want connect 2 tables we will equalise a primary column with foreign column. COUNT query helps to count number of values sin that column and DISTINCT helps to find distinct values 2 | */ 3 | SELECT c.company_code, c.founder, 4 | COUNT(DISTINCT l.lead_manager_code), COUNT(DISTINCT s.senior_manager_code), 5 | COUNT(DISTINCT m.manager_code), COUNT(DISTINCT e.employee_code) 6 | FROM Company c, Lead_Manager l, Senior_Manager s, Manager m, Employee e 7 | WHERE c.company_code = l.company_code AND 8 | l.lead_manager_code = s.lead_manager_code AND 9 | s.senior_manager_code = m.senior_manager_code AND 10 | m.manager_code = e.manager_code 11 | GROUP BY c.company_code, c.founder ORDER BY c.company_code; -------------------------------------------------------------------------------- /Hackerrank/No Idea!/Readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/no-idea/problem -------------------------------------------------------------------------------- /Hackerrank/Number Line Jumps/README.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.hackerrank.com/challenges/kangaroo/problem -------------------------------------------------------------------------------- /Hackerrank/Pangrams/README.md: -------------------------------------------------------------------------------- 1 | Problem link - https://www.hackerrank.com/challenges/pangrams -------------------------------------------------------------------------------- /Hackerrank/Picking Numbers/README.md: -------------------------------------------------------------------------------- 1 | Problem : https://www.hackerrank.com/challenges/picking-numbers/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Pointers/readme.md: -------------------------------------------------------------------------------- 1 | problem link - https://www.hackerrank.com/challenges/c-tutorial-pointer/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Printing Tokens/README.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/printing-tokens-/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Printing Tokens/solution.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | //deeclaring variables 8 | char *s,i; 9 | //dynamic alloacation of variable s 10 | s = malloc(1024 * sizeof(char)); 11 | //input s 12 | scanf("%[^\n]", s); 13 | //resizing memory of s 14 | s = realloc(s, strlen(s) + 1); 15 | //logic to print the tokens of the sentence. 16 | for (char *c = s; *c != NULL; c++) 17 | { 18 | if (*c == ' ') 19 | { 20 | *c = '\n'; 21 | } 22 | } 23 | //output s 24 | printf("%s", s); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Hackerrank/Reverse Linked List/readme.md: -------------------------------------------------------------------------------- 1 | problem link :- https://www.hackerrank.com/challenges/reverse-a-linked-list/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Reverse Linked List/solution.py: -------------------------------------------------------------------------------- 1 | def reverse(head): 2 | 3 | #base conditions 4 | #if head is None or empty return None 5 | if head is None: 6 | return None 7 | #when there is 1 element in list then return head i.e. same list 8 | if head.next is None: 9 | return head 10 | 11 | #call recursion to next element 12 | smallOut = reverse(head.next) 13 | #connect head.next.next = head 14 | #or last element in reversed linked list to current element 15 | head.next.next = head 16 | 17 | #last elment.next = None or end of reversed linked list 18 | head.next = None 19 | 20 | #return reversed linked list 21 | return smallOut 22 | -------------------------------------------------------------------------------- /Hackerrank/Running Time of Algorithms/README.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://www.hackerrank.com/challenges/runningtime/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Sales by Match/README.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/sock-merchant/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=warmup 2 | -------------------------------------------------------------------------------- /Hackerrank/Sales by Match/solution.py: -------------------------------------------------------------------------------- 1 | # The function is expected to return an INTEGER. 2 | # The function accepts following parameters: 3 | # 1. INTEGER n 4 | # 2. INTEGER_ARRAY ar 5 | 6 | def sockMerchant(n, ar): 7 | # Write your code here 8 | # variable to store the pair 9 | a = 0 10 | # Dictionary to store the count 11 | dic = {i: ar.count(i) for i in ar} 12 | for v in dic.values(): 13 | a = a + v // 2 14 | 15 | return a 16 | 17 | 18 | n = int(input().strip()) 19 | 20 | ar = list(map(int, input().rstrip().split())) 21 | 22 | result = sockMerchant(n, ar) 23 | print(result) 24 | -------------------------------------------------------------------------------- /Hackerrank/Sherl/readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/sherlock-and-squares/problem -------------------------------------------------------------------------------- /Hackerrank/SherlockAnagram/readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/sherlock-and-anagrams/problem -------------------------------------------------------------------------------- /Hackerrank/Shrelock and Arrays/readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/sherlock-and-array/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Sparse Arrays/README.md: -------------------------------------------------------------------------------- 1 | Problem link - https://www.hackerrank.com/challenges/sparse-array 2 | -------------------------------------------------------------------------------- /Hackerrank/Staircase/README.md: -------------------------------------------------------------------------------- 1 | Problem : https://www.hackerrank.com/challenges/staircase/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Staircase/solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main () { 6 | int height; 7 | cin >> height; 8 | 9 | for (int i = 1; i <= height; i++) { 10 | for (int j = 0; j < i; j++) { 11 | if(j==0) { 12 | //Printing spaces 13 | for(int t = 0; t < height - i; t++) cout << " "; 14 | } 15 | //Print hashes 16 | cout << "#"; 17 | } 18 | cout << endl; 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Hackerrank/Strange Counter/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://www.hackerrank.com/challenges/strange-code/problem -------------------------------------------------------------------------------- /Hackerrank/Sum of Digits of a Five Digit Number/README.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/sum-of-digits-of-a-five-digit-number/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Sum of Digits of a Five Digit Number/solution.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | //declaring variables 8 | int n,l,sum,i; 9 | //input n 10 | scanf("%d", &n); 11 | //for loop to calculate the sum of digits 12 | for(i=0;i<=5;i++) 13 | { 14 | l=n%10; 15 | sum=sum+l; 16 | n=n/10; 17 | } 18 | //output sum 19 | printf("%d",sum); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Hackerrank/Swap Nodes/readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/swap-nodes-algo/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Time Conversion/read.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/time-conversion/problem -------------------------------------------------------------------------------- /Hackerrank/Variable Sized Arrays/README.md: -------------------------------------------------------------------------------- 1 | Problem Link :- https://www.hackerrank.com/challenges/variable-sized-arrays/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Whats Your Name/readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/whats-your-name/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Write a Function/readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/write-a-function/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/Zig Zag Sequence/readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/zig-zag-sequence/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/compare-the-triplets/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link - https://www.hackerrank.com/challenges/compare-the-triplets/problem -------------------------------------------------------------------------------- /Hackerrank/compare-the-triplets/solution.py: -------------------------------------------------------------------------------- 1 | # taking point input for alice and bob 2 | alice = list(map(int, input().split())) 3 | bob = list(map(int, input().split())) 4 | aliceScore = 0 5 | bobScore = 0 6 | 7 | # comparing the points 8 | for i in range(3): 9 | if alice[i] > bob[i]: 10 | aliceScore += 1 11 | elif alice[i] < bob[i]: 12 | bobScore += 1 13 | print(aliceScore, bobScore) 14 | 15 | 16 | ''' for example Test case 17 | input - 17 28 30 18 | 99 16 8 19 | output - 2 1 20 | ''' 21 | -------------------------------------------------------------------------------- /Hackerrank/drawingbook/README.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/drawing-book/problem 2 | -------------------------------------------------------------------------------- /Hackerrank/kangaroo/readme.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | Link https://www.hackerrank.com/challenges/kangaroo/problem 4 | -------------------------------------------------------------------------------- /Hackerrank/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/polar coordinates/readme.md: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/polar-coordinates/problem -------------------------------------------------------------------------------- /Hackerrank/polar coordinates/solution.py: -------------------------------------------------------------------------------- 1 | #code to implement few methods of cmath module 2 | import cmath 3 | num=complex(input()) 4 | #takes input of the form a +ib where a,b are any real numbers 5 | print(abs(num)) #abs(num) returns absolute value or mod of complex number (a^2+b^2)^0.5 6 | print(cmath.phase(num)) #returns phase in complex plane i.e arctan(b/a) 7 | -------------------------------------------------------------------------------- /InterviewBit/Best Time to Buy and Sell Stock atmost B times/readme.md: -------------------------------------------------------------------------------- 1 | Problem link: https://www.interviewbit.com/problems/best-time-to-buy-and-sell-stock-atmost-b-times/ 2 | -------------------------------------------------------------------------------- /InterviewBit/Fibonnacci Number/readme.md: -------------------------------------------------------------------------------- 1 | problem link: https://www.interviewbit.com/problems/find-nth-fibonacci/ -------------------------------------------------------------------------------- /InterviewBit/Find Duplicate in Array/readme.md: -------------------------------------------------------------------------------- 1 | Problem link: https://www.interviewbit.com/problems/find-duplicate-in-array/ -------------------------------------------------------------------------------- /InterviewBit/Hotel Bookings Possible/readme.md: -------------------------------------------------------------------------------- 1 | Problem link: https://www.interviewbit.com/problems/hotel-bookings-possible/ -------------------------------------------------------------------------------- /InterviewBit/Max Product Subarray/readme.md: -------------------------------------------------------------------------------- 1 | Problem link: https://www.interviewbit.com/problems/max-product-subarray -------------------------------------------------------------------------------- /InterviewBit/Number of 1 bits/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://www.interviewbit.com/problems/number-of-1-bits/ -------------------------------------------------------------------------------- /InterviewBit/Number of 1 bits/solution.cpp: -------------------------------------------------------------------------------- 1 | int Solution::numSetBits(unsigned int A) { 2 | int rem,count = 0; 3 | while(A) 4 | { 5 | A= A&(A-1); //this finds the next 1 position 6 | count++; 7 | } 8 | return count; 9 | } -------------------------------------------------------------------------------- /InterviewBit/Pick from both sides/readme.md: -------------------------------------------------------------------------------- 1 | https://www.interviewbit.com/old/problems/pick-from-both-sides/ 2 | -------------------------------------------------------------------------------- /InterviewBit/Pick from both sides/solution.cpp: -------------------------------------------------------------------------------- 1 | int Solution::solve(vector &a, int b) { 2 | long i,j,k,l,c=0,sum=0,left,right,temp; 3 | for(i=0;i=0) 13 | { 14 | temp=temp-a[left]+a[right]; //excluding the elements from the first b elements and adding elements from the last one by one 15 | if(temp>sum) 16 | sum=temp; // storing the value of temp in sum if temp is greater than the current value of sum 17 | left--; 18 | right--; 19 | } 20 | return sum; 21 | } 22 | -------------------------------------------------------------------------------- /InterviewBit/Rotated Sorted Array Search/readme.md: -------------------------------------------------------------------------------- 1 | https://www.interviewbit.com/problems/rotated-sorted-array-search/ 2 | -------------------------------------------------------------------------------- /InterviewBit/find-duplicate-in-array/readme.md: -------------------------------------------------------------------------------- 1 | https://www.interviewbit.com/problems/find-duplicate-in-array/ 2 | -------------------------------------------------------------------------------- /Leetcode/ Check If N and Its Double Exist/readme.md: -------------------------------------------------------------------------------- 1 | ## Check If N and Its Double Exist 2 | 3 | Difficulty: Easy 4 | 5 | Problem link: https://leetcode.com/problems/check-if-n-and-its-double-exist/ 6 | 7 | -------------------------------------------------------------------------------- /Leetcode/3 Sum Closest/readme.md: -------------------------------------------------------------------------------- 1 | Leetcode : https://leetcode.com/problems/3sum-closest/] 2 | Leetcode Medium 3 | -------------------------------------------------------------------------------- /Leetcode/3Sum/Readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | 3 | https://leetcode.com/problems/3sum/ -------------------------------------------------------------------------------- /Leetcode/4Sum/README.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | 3 | https://leetcode.com/problems/4sum/ 4 | -------------------------------------------------------------------------------- /Leetcode/All Possible Binary Trees/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | 3 | Link : https://leetcode.com/problems/all-possible-full-binary-trees/ -------------------------------------------------------------------------------- /Leetcode/Arithmetic Subarrays/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | Link : https://leetcode.com/problems/arithmetic-subarrays/ 3 | -------------------------------------------------------------------------------- /Leetcode/Best Time To Buy And Sell A Stock/Solution2.cpp: -------------------------------------------------------------------------------- 1 | //Profit = Selling price - purchase price 2 | //With each loop, we compare prices[i] element with the previous minimum value and update accordingly 3 | //With each loop, we compute profit , if the value of profit is greater than the previous value, update profit to get max profit. 4 | 5 | 6 | class Solution { 7 | public: 8 | int maxProfit(vector& prices) { 9 | int profit=0; 10 | int min_value=prices[0]; 11 | for(int i=1;i& prices) { 4 | int maxPro = 0; //Variable to store the maximum profit 5 | for(int i = 0; i < prices.size() - 1; i++){ 6 | if(prices[i] < prices[i+1]){ 7 | maxPro += prices[i+1] - prices[i]; //Keep on adding profits to maxPro 8 | } 9 | } 10 | return maxPro; 11 | } 12 | -------------------------------------------------------------------------------- /Leetcode/Best Time to Buy and Sell Stock II/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxProfit(int[] prices) { 3 | 4 | // Initialize the profit value 5 | int profit = 0; 6 | 7 | // Loop through for the 'length-of-array' times 8 | for(int i=1; i < prices.length; i++){ 9 | 10 | // If the difference in values is positive, add them to profit 11 | if((prices[i] - prices[i-1]) > 0) 12 | profit += (prices[i] - prices[i-1]) ; 13 | } 14 | 15 | // Return profit 16 | return profit; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Leetcode/Best Time to Buy and Sell Stock/Readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Easy 2 | 3 | Link : https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ -------------------------------------------------------------------------------- /Leetcode/Binary Subarrays With Sum/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/binary-subarrays-with-sum/ 2 | -------------------------------------------------------------------------------- /Leetcode/Binary Tree Inorder Traversal/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Easy 2 | Link to problem: https://leetcode.com/problems/binary-tree-inorder-traversal/ 3 | -------------------------------------------------------------------------------- /Leetcode/Binary Tree Level Order Traversal/readme.md: -------------------------------------------------------------------------------- 1 | ## Binary Tree Level Order Traversal 2 | 3 | Difficulty: Medium 4 | 5 | Problem Link: https://leetcode.com/problems/binary-tree-level-order-traversal/ 6 | -------------------------------------------------------------------------------- /Leetcode/Binary Tree Maximum Path Sum/readme.md: -------------------------------------------------------------------------------- 1 | ## Binary Tree Maximum Path Sum 2 | 3 | Difficulty: Hard 4 | 5 | Problem link: https://leetcode.com/problems/binary-tree-maximum-path-sum/ 6 | -------------------------------------------------------------------------------- /Leetcode/Binary Tree Pre Order Traversal/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Easy 2 | 3 | Link : https://leetcode.com/problems/binary-tree-preorder-traversal/ -------------------------------------------------------------------------------- /Leetcode/Binary Tree post order traversal/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Easy 2 | 3 | Link : https://leetcode.com/problems/binary-tree-postorder-traversal/ -------------------------------------------------------------------------------- /Leetcode/BinarySearch/Readme.md: -------------------------------------------------------------------------------- 1 | Difficult : Easy 2 | 3 | Link : https://leetcode.com/problems/binary-search/ 4 | -------------------------------------------------------------------------------- /Leetcode/Brick Wall/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Medium 2 | 3 | LINK TO THE PROBLEM: https://leetcode.com/problems/brick-wall/ 4 | -------------------------------------------------------------------------------- /Leetcode/Build Array from Permutation/README.md: -------------------------------------------------------------------------------- 1 | Problem Name: Build Array from Permutation 2 | Difficulty: Easy 3 | Problem link: https://leetcode.com/problems/build-array-from-permutation/ 4 | -------------------------------------------------------------------------------- /Leetcode/Build Array from Permutation/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] buildArray(int[] nums) { 3 | int[] ans = new int[nums.length];//Initialized an array to store the result// 4 | 5 | for (int i=0;i=0) dp[i]+=dp[i-2]; 12 | } 13 | 14 | // ans must be recieved at last index. 15 | return dp[dp.length-1]; 16 | } 17 | } -------------------------------------------------------------------------------- /Leetcode/Coin Change Two/Readme.md: -------------------------------------------------------------------------------- 1 | # Coin Change 2 2 | Difficulty: Medium 3 | 4 | Problem link: https://leetcode.com/problems/coin-change-2/ 5 | -------------------------------------------------------------------------------- /Leetcode/Combination Sum iii/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | Problem Link : https://leetcode.com/problems/combination-sum-iii/ 3 | -------------------------------------------------------------------------------- /Leetcode/Combination Sum/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Medium 2 | 3 | Link to problem: https://leetcode.com/problems/combination-sum/ 4 | -------------------------------------------------------------------------------- /Leetcode/Combinations/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Medium 2 | Link to the problem: https://leetcode.com/problems/combinations/ 3 | -------------------------------------------------------------------------------- /Leetcode/Concatenation of Array/README.md: -------------------------------------------------------------------------------- 1 | Problem name: Concatenation of Array 2 | Difficulty: Easy 3 | Problem link: https://leetcode.com/problems/concatenation-of-array/ 4 | -------------------------------------------------------------------------------- /Leetcode/Concatenation of Array/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] getConcatenation(int[] nums) { 3 | int[] ans = new int[2*(nums.length)];//Initialised an array of size 2*n to store the result// 4 | for(int i=0; i 3 | Container with Most Water 4 |
5 | Link :- https://leetcode.com/problems/container-with-most-water/ 6 | -------------------------------------------------------------------------------- /Leetcode/Contains Duplicate/readme.md: -------------------------------------------------------------------------------- 1 | ### Contains Duplicate 2 | **Link**: https://leetcode.com/problems/contains-duplicate/ 3 | **Difficulty**: Easy 4 | -------------------------------------------------------------------------------- /Leetcode/Contains Duplicate/solution.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def containsDuplicate(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: bool 6 | """ 7 | ## storing unique elements in a list 8 | unique = [] 9 | for i in nums: 10 | ## if element not in the list, add it to the list 11 | if i not in unique: 12 | unique.append(i) 13 | ## otherwise, return True (i.e. the given list contains duplicates) 14 | else: 15 | return True 16 | 17 | return False -------------------------------------------------------------------------------- /Leetcode/Convert Sorted Array to Binary Search Tree/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ -------------------------------------------------------------------------------- /Leetcode/Convert Sorted List to Binary Search Tree/readme.md: -------------------------------------------------------------------------------- 1 | ## Convert Sorted List to Binary Search Tree 2 | 3 | Difficulty: Medium 4 | 5 | Problem link: https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/ -------------------------------------------------------------------------------- /Leetcode/Copy list with random pointers/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | Problem Link : https://leetcode.com/problems/copy-list-with-random-pointer/ -------------------------------------------------------------------------------- /Leetcode/Count Inversions/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/global-and-local-inversions/ -------------------------------------------------------------------------------- /Leetcode/Count Negative Numbers in a Sorted Matrix/readme.md: -------------------------------------------------------------------------------- 1 | ## Count Negative Numbers in a Sorted Matrix 2 | Difficult: Easy 3 | 4 | Problem Link: https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/ -------------------------------------------------------------------------------- /Leetcode/Count Number Of Consistent Strings/readme.md: -------------------------------------------------------------------------------- 1 | ## Count the Number of Consistent Strings 2 | Difficult: Easy 3 | 4 | Problem Link: https://leetcode.com/problems/count-the-number-of-consistent-strings/ -------------------------------------------------------------------------------- /Leetcode/Count Numbers with Unique Digits/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | Link to the problem : https://leetcode.com/problems/count-numbers-with-unique-digits/ 3 | -------------------------------------------------------------------------------- /Leetcode/Count Numbers with Unique Digits/solution.cpp: -------------------------------------------------------------------------------- 1 | /** Approach: We can calculate by recursively calculation for n and n-1 **/ 2 | 3 | 4 | class Solution { 5 | public: 6 | int countNumbersWithUniqueDigits(int n) { 7 | if(n == 0) 8 | return 1; 9 | int counter = 9, x = 9; 10 | for(int i = 1; i < n; i++){ 11 | counter *= x; 12 | x--; 13 | } 14 | return counter+countNumbersWithUniqueDigits(n-1); 15 | } 16 | }; -------------------------------------------------------------------------------- /Leetcode/Count Sorted Vowel Strings/readme.md: -------------------------------------------------------------------------------- 1 | ## Count Negative Numbers in a Sorted Matrix 2 | Difficult: Easy 3 | 4 | Problem Link: https://leetcode.com/problems/count-sorted-vowel-strings/ -------------------------------------------------------------------------------- /Leetcode/Count-good-triplets/readme.md: -------------------------------------------------------------------------------- 1 | Link: https://leetcode.com/problems/count-good-triplets/ -------------------------------------------------------------------------------- /Leetcode/Count-good-triplets/solution.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Mon Oct 5 2020 4 | @author: Shrey1608 5 | """ 6 | # Approach : 1) using 3 loops for checking the condition(Time complexity O(n^3)| space complexity O(1)) 7 | 8 | 9 | 10 | # Solution:(Approach 1) 11 | class Solution: 12 | def countGoodTriplets(self, arr: List[int], a: int, b: int, c: int) -> int: 13 | n=len(arr) 14 | count=0 15 | for i in range(n-2): 16 | for j in range(i+1,n-1): 17 | if (abs(arr[i] - arr[j]) > a): 18 | continue 19 | for k in range(j+1,n): 20 | if (abs(arr[j] - arr[k]) <= b and abs(arr[i] - arr[k]) <= c): 21 | count+=1 22 | return count -------------------------------------------------------------------------------- /Leetcode/Course Schedule/readme.md: -------------------------------------------------------------------------------- 1 | ### Contains Duplicate 2 | **Link**: https://leetcode.com/problems/course-schedule/ 3 | **Difficulty**: Medium -------------------------------------------------------------------------------- /Leetcode/DailyTempratures/readme.md: -------------------------------------------------------------------------------- 1 | Given an array of integers temperatures represents the daily temperatures, 2 | return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. 3 | If there is no future day for which this is possible, keep answer[i] == 0 instead. 4 | 5 | link: https://leetcode.com/problems/daily-temperatures/ -------------------------------------------------------------------------------- /Leetcode/Deepest Leaves Sum/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | 3 | Link : https://leetcode.com/problems/deepest-leaves-sum/ -------------------------------------------------------------------------------- /Leetcode/Delete Leaves with a given Value/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | 3 | Link : https://leetcode.com/problems/delete-leaves-with-a-given-value/ 4 | -------------------------------------------------------------------------------- /Leetcode/Diameter Of The Binary Tree/Readme.md: -------------------------------------------------------------------------------- 1 | DESCRIPTION : EASY 2 | 3 | LINK : https://leetcode.com/problems/diameter-of-binary-tree/ 4 | -------------------------------------------------------------------------------- /Leetcode/Distinct subsequences/readme.md: -------------------------------------------------------------------------------- 1 | **Distinct Subsequences** 2 | 3 |
4 | 5 | **Leetcode Hard** 6 | 7 |
8 | 9 | **Link**: https://leetcode.com/problems/distinct-subsequences/ -------------------------------------------------------------------------------- /Leetcode/Dungeon Game/readme.md: -------------------------------------------------------------------------------- 1 | Link to problem : https://leetcode.com/problems/dungeon-game/ -------------------------------------------------------------------------------- /Leetcode/Edit Distance/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/edit-distance/ -------------------------------------------------------------------------------- /Leetcode/Evaluate Reverse Polish Notation/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Medium 2 | Link to the problem: https://leetcode.com/problems/evaluate-reverse-polish-notation/ -------------------------------------------------------------------------------- /Leetcode/Fibonacci Number/Readme.md: -------------------------------------------------------------------------------- 1 | Difficulty level - Easy 2 | 3 | https://leetcode.com/problems/fibonacci-number/ -------------------------------------------------------------------------------- /Leetcode/Fibonacci Number/fibonacci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int fib(int n) { // Function to find nth fibonacci number 4 | if(n==0) //Base case for recursion 5 | return 0; 6 | if(n==1) 7 | return 1; 8 | int fi=fib(n-1)+fib(n-2); //using recursion 9 | return fi; 10 | } 11 | int main() 12 | { 13 | int n; 14 | cout<<"Enter number"<>n; 16 | cout< finalPrices(vector& prices) { 4 | int n=prices.size(); // n contains vector size 5 | for( int i=0;i 2 | class Solution 3 | { 4 | public: 5 | int findGCD(vector &nums) 6 | { 7 | int n = nums.size(); //Storing size of vector 8 | 9 | sort(nums.begin(), nums.end()); //Sorting the vector 10 | 11 | int gcd = __gcd(nums[0], nums[n - 1]); //Finding GCD of largest and smallest number 12 | 13 | return gcd; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Leetcode/Find Median from Data Stream/README.md: -------------------------------------------------------------------------------- 1 | 2 | Problem : https://leetcode.com/problems/find-median-from-data-stream/ 3 | -------------------------------------------------------------------------------- /Leetcode/Find Minimum in Rotated Sorted Array II/Readme.md: -------------------------------------------------------------------------------- 1 | ## Find Minimum in Rotated Sorted Array II 2 | 3 | Difficulty : Hard 4 | 5 | Problem Link : https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/ 6 | 7 | -------------------------------------------------------------------------------- /Leetcode/Find Minimum in Rotated Sorted Array/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/ 2 | -------------------------------------------------------------------------------- /Leetcode/Find Smallest Letter Greater Than Target/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Easy 2 | Approch: Using Binary Search Algorithm 3 | 4 | Problem link: https://leetcode.com/problems/find-smallest-letter-greater-than-target/ -------------------------------------------------------------------------------- /Leetcode/Find Smallest Letter Greater Than Target/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public char nextGreatestLetter(char[] letters, char target) { 3 | int start = 0; 4 | int end = letters.length - 1; 5 | while(start <= end){ 6 | int mid = (start + end)/2; 7 | //if target element is less than middle element 8 | if(target < letters[mid] ){ 9 | end = mid -1; 10 | } 11 | //target element is greater than mid element 12 | else { 13 | start = mid +1; 14 | } 15 | } 16 | //condition of the wrap around 17 | return letters[start%letters.length]; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Leetcode/Find all duplicates in an array/readme.md: -------------------------------------------------------------------------------- 1 | Leetcode Find all duplicates in an array(Medium) https://leetcode.com/problems/find-all-duplicates-in-an-array/ -------------------------------------------------------------------------------- /Leetcode/Find first missing positive/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Hard 2 | 3 | Problem Link : https://leetcode.com/problems/first-missing-positive/ 4 | -------------------------------------------------------------------------------- /Leetcode/Find the Highest Altitude/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int largestAltitude(vector& gain) { 4 | vector alt(gain.size()+1,0); // vector alt defined 5 | 6 | for(int i=1;i 3 | First Missing Positive 4 |
5 | Link to Problem: https://leetcode.com/problems/first-missing-positive/ -------------------------------------------------------------------------------- /Leetcode/First unique character in sting/readme.md: -------------------------------------------------------------------------------- 1 | Link to problem : https://leetcode.com/problems/first-unique-character-in-a-string/ -------------------------------------------------------------------------------- /Leetcode/Flipping an image/README.md: -------------------------------------------------------------------------------- 1 | Leetcode Easy 2 |
3 | Flipping and Image 4 |
5 | Link : https://leetcode.com/problems/flipping-an-image/ 6 | -------------------------------------------------------------------------------- /Leetcode/Frog Jump/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/frog-jump/ -------------------------------------------------------------------------------- /Leetcode/Gas station/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link: https://leetcode.com/problems/gas-station/ -------------------------------------------------------------------------------- /Leetcode/Gray Code/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | 3 | https://leetcode.com/problems/gray-code/ 4 | -------------------------------------------------------------------------------- /Leetcode/Gray Code/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector grayCode(int n) { 4 | // since, every integer is in the inclusive range [0,2^n-1] 5 | // therefore, we can use 2^n as upper-limit 6 | // lets store this upper limit in variable ul 7 | int ul=pow(2,n); 8 | // crreate an "ans" vector that will store the desired outputs 9 | vector ans; 10 | for(int i=0;i>1) i.e. binary representation of "i" right shifted by 1 bit" 12 | ans.push_back(i^(i>>1)); 13 | } 14 | // finally, return the output vector 15 | return ans; 16 | } 17 | }; -------------------------------------------------------------------------------- /Leetcode/Group Anagrams/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Medium 2 | 3 | Link to problem: https://leetcode.com/problems/group-anagrams/ 4 | -------------------------------------------------------------------------------- /Leetcode/Group the People Given the Group Size They Belong To/Readme.md: -------------------------------------------------------------------------------- 1 | ### Group the People Given the Group Size They Belong To 2 | 3 | **Link**: https://leetcode.com/problems/group-the-people-given-the-group-size-they-belong-to/ 4 | **Difficulty**: Medium 5 | -------------------------------------------------------------------------------- /Leetcode/Group the People Given the Group Size They Belong To/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]: 3 | dic = {} 4 | # First we add all people into dictionary where key will be the group size. 5 | for i in range(len(groupSizes)): 6 | if groupSizes[i] in dic: 7 | dic[groupSizes[i]].append(i) 8 | else: 9 | dic[groupSizes[i]] = [i] 10 | res = [] 11 | print(dic) 12 | # Here we just separate the people into different groups according to the group sizes 13 | for k, v in dic.items(): 14 | for i in range(0, len(v), k): 15 | res.append(v[i:i+k]) 16 | return res 17 | -------------------------------------------------------------------------------- /Leetcode/Happy Number/Readme.md: -------------------------------------------------------------------------------- 1 | ### HAPPY NUMBER 2 | 3 | Link to the problem --> https://leetcode.com/problems/happy-number/ 4 | -------------------------------------------------------------------------------- /Leetcode/House Robber/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | Link : https://leetcode.com/problems/house-robber/ -------------------------------------------------------------------------------- /Leetcode/Implement strStr/readme.md: -------------------------------------------------------------------------------- 1 |

Implement strStr()

2 |
3 | Difficulty : Easy 4 |
5 | Link to problem: https://leetcode.com/problems/implement-strstr/ 6 | -------------------------------------------------------------------------------- /Leetcode/Increasing Triplet Subsequence/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Medium 2 | Problem Link: https://leetcode.com/problems/increasing-triplet-subsequence/ 3 | -------------------------------------------------------------------------------- /Leetcode/Insert into a binary search tree/readme.md: -------------------------------------------------------------------------------- 1 | ## Insert into a Binary Search Tree 2 | 3 | Difficulty: Medium 4 | 5 | Problem link: https://leetcode.com/problems/insert-into-a-binary-search-tree/ -------------------------------------------------------------------------------- /Leetcode/Integer to English Words/README.md: -------------------------------------------------------------------------------- 1 | Leetcode Hard 2 |
3 | Integer to English Words 4 |
5 | Link : https://leetcode.com/problems/integer-to-english-words/ 6 | -------------------------------------------------------------------------------- /Leetcode/Intersection of Two Arrays II/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Easy 2 | 3 | Link to problem: https://leetcode.com/problems/intersection-of-two-arrays-ii/ 4 | -------------------------------------------------------------------------------- /Leetcode/Is Graph Bipartite/README.md: -------------------------------------------------------------------------------- 1 | ### Is Graph Bipartite? 2 | 3 | **Link**: https://leetcode.com/problems/is-graph-bipartite/ 4 | **Difficulty**: Medium -------------------------------------------------------------------------------- /Leetcode/Jump Game 2/README.md: -------------------------------------------------------------------------------- 1 | Dificulty : Medium 2 | 3 | Link : [ Jump Game II ]( https://leetcode.com/problems/jump-game-ii/ ) 4 | *** 5 | 6 | -------------------------------------------------------------------------------- /Leetcode/Jump Game/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canJump(int[] nums) { 3 | if(nums.length==1) 4 | return true; //If there is only one element, then it is possible to jump to it. 5 | int dist = 0; 6 | for(int i = 0; i < nums.length; i++){ 7 | dist=Math.max(dist, nums[i]); //Find the farthest distance that can be reached from the current position. 8 | if(dist==0 && i!=nums.length-1) 9 | return false; //If the farthest distance is 0, then it is impossible to reach the end. 10 | dist--; //Reduce the farthest distance by 1. 11 | } 12 | return true; //If the farthest distance is not 0, then it is possible to reach the end. 13 | } 14 | } -------------------------------------------------------------------------------- /Leetcode/Jump Game/readme.md: -------------------------------------------------------------------------------- 1 | ## Jump Game 2 | 3 | Difficulty: Medium 4 | 5 | Problem link: https://leetcode.com/problems/jump-game/ 6 | 7 | -------------------------------------------------------------------------------- /Leetcode/Jump Game/solution.cpp: -------------------------------------------------------------------------------- 1 | //Explaination: At each iteration we have to check the maximum index we can reach from the current index we are at and update it. 2 | // TC : O(n) 3 | 4 | class Solution { 5 | public: 6 | bool canJump(vector& nums) { 7 | int maxReach = 0;//Let this be the maximum we can reach. 8 | 9 | for(int i = 0; i < nums.size(); i++) { 10 | //If we can reach this index, then update the maxReach possible. 11 | if(i <= maxReach) { 12 | maxReach = max(maxReach, i + nums[i]); //Updating the maxReach. 13 | } 14 | } 15 | 16 | return maxReach >= nums.size() - 1; // if we are able to reach the end or not.(since we have to return boolean) 17 | } 18 | }; -------------------------------------------------------------------------------- /Leetcode/Jump Game/solution2.cpp: -------------------------------------------------------------------------------- 1 | //jump game 2 | //The idea is to use a variable maxrange which will tell you the maximum jump possible , and run a loop if i>maxrange then it will return 0 otherwise it will return 1 . 3 | 4 | class Solution { 5 | public: 6 | bool canJump(vector& nums) { 7 | int n=nums.size(); 8 | if(n==1) return 1; 9 | 10 | int maxrange = nums[0]; 11 | for(int i=1;i=n-1) return 1; 13 | if(maxrange>=i&&i!=0) maxrange = max(maxrange,i+nums[i]); 14 | else return 0; 15 | } 16 | return -1; //we are never going to return this value 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Leetcode/K-Concatenation Maximum Sum/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | Link : https://leetcode.com/problems/k-concatenation-maximum-sum/ -------------------------------------------------------------------------------- /Leetcode/K-th Symbol in Grammar/Readme.md: -------------------------------------------------------------------------------- 1 | # K-th Symbol in Grammar 2 | Difficulty: Medium 3 | 4 | Problem link: https://leetcode.com/problems/k-th-symbol-in-grammar/ 5 | -------------------------------------------------------------------------------- /Leetcode/K-th Symbol in Grammar/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int kthGrammar(int n, int k) { 3 | if(n == 1) return 0; 4 | 5 | // Even children are right childs 6 | // 0's right child is 1 7 | // 1's right child is 0 8 | if(k % 2 == 0) return (kthGrammar(n-1, k / 2) == 0) ? 1 : 0; 9 | 10 | 11 | // Odd children are left childs 12 | // 0's left child is 0 13 | // 1's left child is 1 14 | return (kthGrammar(n-1, (k + 1) / 2) == 0) ? 0 : 1; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Leetcode/Kids With the Greatest Number of Candies/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/ -------------------------------------------------------------------------------- /Leetcode/Kids With the Greatest Number of Candies/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector kidsWithCandies(vector& candies, int extraCandies) { 4 | // find the maximum number of candy the kid has 5 | int max = *max_element(candies.begin(),candies.end()); 6 | vector arr; 7 | for (int i=0;i>& matrix, int k) { 7 | vectorv; 8 | for(int i=0;i &nums) 5 | { 6 | sort(nums.begin(), nums.end()); //Sorting the array 7 | for (int i = nums.size()-1; i >= 2; i--) 8 | { 9 | if (nums[i - 1] + nums[i - 2] > nums[i]) //Checking whether the property of sides of triangle is valid for the set of numbers 10 | { 11 | return nums[i] + nums[i - 1] + nums[i - 2]; //Calculating perimeter 12 | } 13 | } 14 | return 0; 15 | } 16 | }; -------------------------------------------------------------------------------- /Leetcode/Largest Rectangle in Histogram/readme.md: -------------------------------------------------------------------------------- 1 | ## Largest Rectangle in Histogram 2 | 3 | Difficulty: Hard 4 | 5 | Problem link: https://leetcode.com/problems/largest-rectangle-in-histogram/ 6 | -------------------------------------------------------------------------------- /Leetcode/Last Stone Weight/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Easy 2 | 3 | Link : https://leetcode.com/problems/last-stone-weight/ -------------------------------------------------------------------------------- /Leetcode/Last Stone Weight/solution.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Last Stone Weight solution in C++ 3 | Author: Shourya Gupta 4 | */ 5 | 6 | class Solution { 7 | public: 8 | int lastStoneWeight(vector& stones) { 9 | 10 | while(stones.size()!=1){//run the loop until only one element remains 11 | int rem=0; 12 | sort(stones.begin(), stones.end()); //Sorting the stones array 13 | rem=stones[stones.size()-1]-stones[stones.size()-2];//After smashing the new weight obtained 14 | stones.pop_back();//removed the heaviest weight 15 | stones.pop_back();//removed the 2nd largest weight 16 | stones.push_back(rem);//input the new remaining weight 17 | } 18 | return stones[0]; 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /Leetcode/Letter Combination of Phone number/Readme.md: -------------------------------------------------------------------------------- 1 | 17. Letter Combinations of a Phone Number 2 | 3 | Difficulty: Medium 4 | 5 | Problem link: https://leetcode.com/problems/letter-combinations-of-a-phone-number/ -------------------------------------------------------------------------------- /Leetcode/Linked List Cycle/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Easy 2 | 3 | Link : https://leetcode.com/problems/linked-list-cycle/ -------------------------------------------------------------------------------- /Leetcode/Longest Common Prefix/README.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/longest-common-prefix/ 2 | -------------------------------------------------------------------------------- /Leetcode/Longest Common Prefix/solution.cpp: -------------------------------------------------------------------------------- 1 | char * longestCommonPrefix(char ** strs, int strsSize) 2 | { 3 | // if string size is 0 then return "". 4 | if(strsSize==0) return ""; 5 | // simple run a for loop while fixing first element and then compare it with others. 6 | for(int i=0;i>& mat) { 4 | int n=mat.size(),sum=0; // variables n (assigned size of the vector mat) and sum 5 | for (int i=0;i int: 6 | res = 0 7 | for i in range(len(grid)): 8 | for j in range(len(grid[0])): 9 | res += abs(grid[i][j] - min(max(grid[i]), 10 | max([g[j] for g in grid]))) 11 | return res 12 | -------------------------------------------------------------------------------- /Leetcode/Max Points on a Line/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Hard 2 | 3 | Link to problem: https://leetcode.com/problems/max-points-on-a-line/ 4 | -------------------------------------------------------------------------------- /Leetcode/Maximize Distance to Closest Person/README.md: -------------------------------------------------------------------------------- 1 | Leetcode Medium 2 |
3 | Maximize Distance to Closest Person 4 |
5 | Link : https://leetcode.com/problems/maximize-distance-to-closest-person/ 6 | -------------------------------------------------------------------------------- /Leetcode/Maximum Depth of Binary Tree/readme.md: -------------------------------------------------------------------------------- 1 | ## Maximum Depth of Binary Tree 2 | 3 | Difficulty: Easy 4 | 5 | Problem Link: https://leetcode.com/problems/maximum-depth-of-binary-tree/ -------------------------------------------------------------------------------- /Leetcode/Maximum Depth of Binary Tree/solution.cpp: -------------------------------------------------------------------------------- 1 | // Recursive Approach: 2 | // Find maximum depth of the left subtree and store it to a variable leftHeight lets say 3 | // Similarly find maximum depth of the right subtree and save it 4 | // Maximum depth for the current subtree will be maximum of leftDepth and rightDepth plus 1 5 | // Add 1 to include the current node 6 | class Solution { 7 | public: 8 | int maxDepth(TreeNode* root) { 9 | if(root == NULL) 10 | return 0; 11 | int leftDepth = maxDepth(root->left); 12 | int rightDepth = maxDepth(root->right); 13 | return max(leftDepth, rightDepth) + 1; 14 | } 15 | }; -------------------------------------------------------------------------------- /Leetcode/Maximum Population Year/README.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/maximum-population-year/ -------------------------------------------------------------------------------- /Leetcode/Maximum Product Subarray/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Medium 2 | 3 | Question link: [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray/) -------------------------------------------------------------------------------- /Leetcode/Maximum Product of Three Numbers/Readme.md: -------------------------------------------------------------------------------- 1 | ## Maximum Product of 3 Numbers 2 | 3 | Difficulty: Easy 4 | 5 | Problem: https://leetcode.com/problems/maximum-product-of-three-numbers/ 6 | -------------------------------------------------------------------------------- /Leetcode/Maximum Product of Three Numbers/Solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int maximumProduct(vector &nums) 5 | { 6 | sort(nums.begin(), nums.end()); //Sorting the given vector 7 | 8 | int n = nums.size(); 9 | 10 | int product1 = nums[0] * nums[1] * nums[n - 1]; //Calculating maximum of 1 set of numbers 11 | int product2 = nums[n - 1] * nums[n - 2] * nums[n - 3]; //Calculating maximum of 2nd set of numbers 12 | 13 | return max(product1, product2); //Returning maximum out of those two sets 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Leetcode/Merge In Between Linked Lists/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/merge-in-between-linked-lists/ -------------------------------------------------------------------------------- /Leetcode/Merge Overlapping Subintervals/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/merge-intervals/ -------------------------------------------------------------------------------- /Leetcode/Merge Sorted Array/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Easy 2 | Problem Link: https://leetcode.com/problems/merge-sorted-array/ -------------------------------------------------------------------------------- /Leetcode/Merge Two Sorted Lists/readme.md: -------------------------------------------------------------------------------- 1 | ## Merge Two Sorted Lists 2 | 3 | Difficulty: Easy 4 | 5 | Problem link: https://leetcode.com/problems/merge-two-sorted-lists/ 6 | -------------------------------------------------------------------------------- /Leetcode/Merge k Sorted Lists/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Hard 2 | 3 | https://leetcode.com/problems/merge-k-sorted-lists/ 4 | -------------------------------------------------------------------------------- /Leetcode/Middle of the Linked List/readme.md: -------------------------------------------------------------------------------- 1 | Problem link: https://leetcode.com/problems/middle-of-the-linked-list/ -------------------------------------------------------------------------------- /Leetcode/Min Cost Climbing Stairs/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/min-cost-climbing-stairs/ -------------------------------------------------------------------------------- /Leetcode/Minimum Absolute Sum Difference/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Medium 2 | 3 | Link: https://leetcode.com/problems/minimum-absolute-sum-difference/ 4 | -------------------------------------------------------------------------------- /Leetcode/Minimum Add to Make Parentheses Valid/readme.md: -------------------------------------------------------------------------------- 1 | ### Minimum Add to Make Parentheses Valid 2 | 3 | **Link**: https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/ 4 | **Difficulty**: Medium 5 | -------------------------------------------------------------------------------- /Leetcode/Minimum Cost to cut stick/readme.md: -------------------------------------------------------------------------------- 1 | Minimum Cost to Cut a Stick : https://leetcode.com/problems/minimum-cost-to-cut-a-stick/ -------------------------------------------------------------------------------- /Leetcode/Minimum Depth of Binary Tree/Readme.md: -------------------------------------------------------------------------------- 1 | # Minimum Depth of Binary Tree 2 | Difficulty: Easy 3 | 4 | Problem link: https://leetcode.com/problems/minimum-depth-of-binary-tree/ 5 | -------------------------------------------------------------------------------- /Leetcode/Minimum Depth of Binary Tree/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minDepth(TreeNode root) { 3 | // base case returning 0 for null nodes 4 | if(root == null) return 0; 5 | 6 | // get the Left and Right heights of the tree 7 | int lH = minDepth(root.left); 8 | int rH = minDepth(root.right); 9 | 10 | // m is the minimum of left and right heights 11 | int m = Math.min(lH, rH); 12 | 13 | // we return 1 plus the minimum height 14 | // if the tree has 2 children 15 | // else return the maximum height 16 | return 1+ (m > 0 ? m : Math.max(lH, rH)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Leetcode/Minimum Height Trees/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | 3 | https://leetcode.com/problems/minimum-height-trees/ 4 | -------------------------------------------------------------------------------- /Leetcode/Minimum Speed to Arrive on Time/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Medium 2 | 3 | Problem link: https://leetcode.com/problems/minimum-speed-to-arrive-on-time/ -------------------------------------------------------------------------------- /Leetcode/Minimum Time to Type Word Using Special Typewriter/readme.md: -------------------------------------------------------------------------------- 1 | Problem link: https://leetcode.com/problems/minimum-time-to-type-word-using-special-typewriter/
2 | -------------------------------------------------------------------------------- /Leetcode/Minimum Window Substring/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Hard 2 | 3 | Link to problem: https://leetcode.com/problems/minimum-window-substring/ 4 | -------------------------------------------------------------------------------- /Leetcode/Missing Number/readme.md: -------------------------------------------------------------------------------- 1 | ## PROBLEM LINK 2 | 3 | https://leetcode.com/problems/missing-number/ 4 | 5 | ### Level: Easy 6 | -------------------------------------------------------------------------------- /Leetcode/Missing Number/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int missingNumber(vector& nums) { 4 | int sum1=0, sum2=0; 5 | for(int i=0;i& nums) { 2 | if(nums.size() < 2) //There is no need to move zeroes if the size is 1 or 0 3 | return; 4 | int index = 0; //Index variable used to populate the array with non-zero values 5 | for(int i = 0; i < nums.size(); i++){ 6 | if(nums[i] != 0){ 7 | nums[index++] = nums[i]; //Non-zero values are copied to the nums[index] and index is incremented 8 | } 9 | } 10 | //The rest of the array can be now filled with zeroes 11 | for(int i = index; i < nums.size(); i++){ 12 | nums[i] = 0; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Leetcode/Multiply Strings/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Medium 2 | Problem Link: https://leetcode.com/problems/multiply-strings/ 3 | -------------------------------------------------------------------------------- /Leetcode/N Queens/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Hard 2 | Problem Link: https://leetcode.com/problems/n-queens/ 3 | -------------------------------------------------------------------------------- /Leetcode/N-Repeated Element in Size 2N Array/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Easy 2 | 3 | https://leetcode.com/problems/n-repeated-element-in-size-2n-array/ 4 | -------------------------------------------------------------------------------- /Leetcode/N-Repeated Element in Size 2N Array/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int repeatedNTimes(vector& nums) { 4 | int n=nums.size(), ans=0; //defining variables 5 | sort(nums.begin(),nums.end()); // sorted vector for easily finding repeated number 6 | for (int i=0;i 3 | Number of Longest Increasing Subsequence 4 |
5 | Link : https://leetcode.com/problems/number-of-longest-increasing-subsequence/ 6 | -------------------------------------------------------------------------------- /Leetcode/Number of BSTs/readme.md: -------------------------------------------------------------------------------- 1 | Unique Binary Search Trees : https://leetcode.com/problems/unique-binary-search-trees/ -------------------------------------------------------------------------------- /Leetcode/Number of Good pairs/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : easy 2 | 3 | link : https://leetcode.com/problems/number-of-good-pairs/ 4 | -------------------------------------------------------------------------------- /Leetcode/Number of Islands/readme.md: -------------------------------------------------------------------------------- 1 | Link to problem: https://leetcode.com/problems/number-of-islands/ 2 | -------------------------------------------------------------------------------- /Leetcode/Number of Pairs of Strings With Concatenation Equal to Target/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | Link : https://leetcode.com/problems/number-of-pairs-of-strings-with-concatenation-equal-to-target/ -------------------------------------------------------------------------------- /Leetcode/Number of Steps to Reduce a Number to Zero/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Easy 2 | 3 | Problem Link: https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero/ 4 | -------------------------------------------------------------------------------- /Leetcode/Number of Students Doing Homework at a Given Time/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Easy 2 | 3 | https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time/ 4 | -------------------------------------------------------------------------------- /Leetcode/Number of Students Doing Homework at a Given Time/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int busyStudent(vector& startTime, vector& endTime, int queryTime) { 4 | int n = startTime.size(), ans = 0; //defining variable 5 | for (int i=0; i= 0; i--) // Run a reverse loop 10 | { 11 | r += s[i]; // append each character to the string r. 12 | } 13 | 14 | if (s == r) // if the actual string is equal to the reversed string 15 | { 16 | return true; // return that the number is palindrome 17 | } 18 | return false; // if they are not equal: return the number is not a palindrome 19 | } 20 | }; -------------------------------------------------------------------------------- /Leetcode/Palindrome Partitioning II/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Hard 2 | 3 | https://leetcode.com/problems/palindrome-partitioning-ii/ 4 | -------------------------------------------------------------------------------- /Leetcode/Palindrome Partitioning/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | Problem Link : https://leetcode.com/problems/palindrome-partitioning/ 3 | -------------------------------------------------------------------------------- /Leetcode/Palindromic Substrings/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Medium 2 | 3 | Question Link:[Palindromic Substrings](https://leetcode.com/problems/palindromic-substrings/) -------------------------------------------------------------------------------- /Leetcode/Partition Equal Subset Sum/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | 3 | Link : https://leetcode.com/problems/partition-equal-subset-sum/ -------------------------------------------------------------------------------- /Leetcode/Partition array for Maximum Sum/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | Link : https://leetcode.com/problems/partition-array-for-maximum-sum/ 3 | -------------------------------------------------------------------------------- /Leetcode/Partition into K Equal Sum Subsets/readme.md: -------------------------------------------------------------------------------- 1 | ## Leetcode: Partition to K Equal Sum Subsets 2 | 3 | Difficulty : Medium 4 | Link:https://leetcode.com/problems/partition-to-k-equal-sum-subsets/ 5 | -------------------------------------------------------------------------------- /Leetcode/Partition to K Equal Sum Subsets/Partition Equal Subset Sum/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Hard 2 | 3 | Link : https://leetcode.com/problems/partition-to-k-equal-sum-subsets/ 4 | -------------------------------------------------------------------------------- /Leetcode/Path Sum/readme.md: -------------------------------------------------------------------------------- 1 | Link to problem: https://leetcode.com/explore/learn/card/data-structure-tree/17/solve-problems-recursively/537/ 2 | -------------------------------------------------------------------------------- /Leetcode/Path With Minimum Effort/readme.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | * Difficulty: Medium 4 | * Problem Link: https://leetcode.com/problems/path-with-minimum-effort/ 5 | 6 | -------------------------------------------------------------------------------- /Leetcode/Peak Index Mountain Array/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | Problem Link - https://leetcode.com/problems/peak-index-in-a-mountain-array/ 4 | 5 | Difficulty:- Easy -------------------------------------------------------------------------------- /Leetcode/Peak Index Mountain Array/Solution.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | public static void main(String[] args) { 4 | 5 | int[] arr = {0,2,4,7,9,11,8,6,5,3,1}; 6 | int ans = search(arr); 7 | System.out.print(ans); 8 | } 9 | 10 | static int search(int[] arr) { 11 | int start = 0; 12 | int end = arr.length-1; 13 | 14 | while(end>start) { 15 | int mid = start + (end-start)/2; 16 | if(arr[mid]>arr[mid+1]) { 17 | // You are in dec part of array 18 | // This may be the ans but look at left too 19 | end = mid; 20 | }else { 21 | //You are in asc part of array 22 | //mid+1 maybe the ans but look at right too 23 | start = mid+1; 24 | } 25 | 26 | } 27 | return start; //also end will be fine 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Leetcode/Permutation Sequence/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Hard 2 | 3 | Link to problem: https://leetcode.com/problems/permutation-sequence/ 4 | -------------------------------------------------------------------------------- /Leetcode/Permutations/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Medium 2 | Link to the problem: https://leetcode.com/problems/permutations/ 3 | -------------------------------------------------------------------------------- /Leetcode/Plus One/readme.md: -------------------------------------------------------------------------------- 1 | Problem link: https://leetcode.com/problems/plus-one/ 2 | -------------------------------------------------------------------------------- /Leetcode/Plus One/solution.py: -------------------------------------------------------------------------------- 1 | """ 2 | We're given a list of digits, and the idea here is to convert that list to an integer, num. So each digit is multiplied by the proper place value and added to num. For example, if digits = [3, 8, 2, 5] then on the first iteration 3 is multiplied by 10 to the power of 4-1-0 = 3, so this results in 3000, which is added to num. Then 8 is multiplied by 10^2 and added to num, and so on. 3 | 4 | The last step is to add 1 to num, convert it to a list and return that list. 5 | """ 6 | 7 | def plusOne(digits): 8 | num = 0 9 | for i in range(len(digits)): 10 | num += digits[i] * pow(10, (len(digits)-1-i)) 11 | return [int(i) for i in str(num+1)] 12 | -------------------------------------------------------------------------------- /Leetcode/Pow-x-n/readme.md: -------------------------------------------------------------------------------- 1 | * Difficulty: Medium 2 | * Problem Link: https://leetcode.com/problems/powx-n/ 3 | -------------------------------------------------------------------------------- /Leetcode/Pow-x-n/solution.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Time complexity = O(log n) 3 | 4 | */ 5 | class Solution { 6 | public: 7 | double calculate(double x,int n){ 8 | 9 | double ans = 1.0; //initialising result 10 | while(n){ 11 | if(n%2) //if power is odd multiply with x 12 | ans = ans*x; 13 | n=n/2; 14 | x=x*x; // convert x to x^2 15 | 16 | } 17 | return ans; 18 | } 19 | double myPow(double x, int n) { 20 | double power = (n<0)?calculate((double)1.0/x,n):calculate(x,n); // If power is negative then finding (1/x)^n 21 | return power; 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /Leetcode/Range sum of BST/readme.md: -------------------------------------------------------------------------------- 1 | Link: https://leetcode.com/problems/range-sum-of-bst/ -------------------------------------------------------------------------------- /Leetcode/Range sum of BST/solution.py: -------------------------------------------------------------------------------- 1 | # Approach : 1) Inorder traversal (DFS) and range(Time complexity= O(H)(h is height of the tree) 2 | 3 | 4 | 5 | #Solution : Inorder traversal and range(DFS) 6 | class Solution: 7 | def rangeSumBST(self, root: TreeNode, L: int, R: int) -> int: 8 | output=[] 9 | self.inorder(root,output) 10 | sum=L+R 11 | for i in range(len(output)): 12 | if output[i]>L and output[i] &A, int B) 8 | { 9 | int cnt = 0; 10 | for (int j = 0; j < A.size(); j++) 11 | { 12 | if (A[j] != B) 13 | { 14 | A[cnt] = A[j]; 15 | cnt++; 16 | } 17 | else // we skip the element 18 | continue; 19 | } 20 | 21 | return cnt; 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /Leetcode/Remove Nth Node From End of List/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/remove-nth-node-from-end-of-list/ -------------------------------------------------------------------------------- /Leetcode/Reorder List/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | Problem Link : https://leetcode.com/problems/reorder-list/ -------------------------------------------------------------------------------- /Leetcode/Reshape the Matrix/readme.md: -------------------------------------------------------------------------------- 1 | Problem Link : https://leetcode.com/problems/reshape-the-matrix/ 2 | -------------------------------------------------------------------------------- /Leetcode/Reverse Integer/README.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/reverse-integer/ -------------------------------------------------------------------------------- /Leetcode/Reverse Integer/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int reverse(int x) { 3 | //variable to store the final reversed integer 4 | long rev = 0; 5 | //we will keep taking mod of the input until we reach zero 6 | while (x != 0) { 7 | //finding remainder 8 | int d = x % 10; 9 | //multiplying by 10 and adding the remainder back to rev 10 | rev = rev * 10 + d; 11 | //stripping off the unit digit 12 | x = x / 10; 13 | } 14 | //checking if our answer is within range 15 | if (rev > Integer.MAX_VALUE || rev < Integer.MIN_VALUE) 16 | return 0; 17 | else 18 | return (int) rev; 19 | } 20 | } -------------------------------------------------------------------------------- /Leetcode/Reverse Linkedlist/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/reverse-linked-list/ -------------------------------------------------------------------------------- /Leetcode/Reverse Linkedlist/solution.cpp: -------------------------------------------------------------------------------- 1 | 2 | class Solution { 3 | public: 4 | ListNode* reverseList(ListNode* head) { 5 | ListNode *dummy_head = new ListNode(0); 6 | dummy_head->next = head; 7 | 8 | //intialise previous node pointing to null 9 | ListNode *prev = nullptr; 10 | 11 | //run while loop till end of list 12 | while(head!=nullptr){ 13 | //initialise next node pointing to the node after the current node 14 | ListNode *next_node = head->next; 15 | 16 | //eg: null->1->2 17 | 18 | head->next = prev; 19 | prev = head; 20 | head = next_node; 21 | 22 | //2->1->null 23 | } 24 | 25 | return prev; 26 | } 27 | }; -------------------------------------------------------------------------------- /Leetcode/Richest Customer Wealth/README.md: -------------------------------------------------------------------------------- 1 | Problem Name: Richest Customer Wealth 2 | Difficulty: Easy 3 | link: https://leetcode.com/problems/richest-customer-wealth/ 4 | -------------------------------------------------------------------------------- /Leetcode/Roman to Integer/README.md: -------------------------------------------------------------------------------- 1 | ### Roman to Integer 2 | **Link**: https://leetcode.com/problems/roman-to-integer/ 3 | **Difficulty**: Easy -------------------------------------------------------------------------------- /Leetcode/Rotate Image/readme.md: -------------------------------------------------------------------------------- 1 | + Difficulty: Medium 2 | + Problem link: https://leetcode.com/problems/rotate-image/ -------------------------------------------------------------------------------- /Leetcode/Rotate Image/solution.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | The simplest way to perform this operation is to - 3 | 1) Take transpose of matrix. 4 | 2) Take mirror image of matrix. 5 | */ 6 | class Solution { 7 | public: 8 | void rotate(vector>& matrix) 9 | { 10 | int n = matrix.size(); 11 | 12 | //Transpose 13 | for( int i=0 ; i singleNumber(vector& nums) { 4 | vectorp; //created vector to store values 5 | unordered_mapmp; // created map to store nums element and their frequency 6 | for(int i=0;i 2 | Shortest Path in a Grid with Obstacles Elimination
3 | Link: https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/ -------------------------------------------------------------------------------- /Leetcode/Shuffle String/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/shuffle-string/ -------------------------------------------------------------------------------- /Leetcode/Shuffle String/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string restoreString(string s, vector& indices) { 4 | // indices contains the order in which each letter should be rearranged 5 | string newStr=s; 6 | for(int i=0;i 2 | Shuffle the Array
3 | Link: https://leetcode.com/problems/shuffle-the-array/ -------------------------------------------------------------------------------- /Leetcode/Sign of the Product of an Array/Readme.md: -------------------------------------------------------------------------------- 1 | ## Sign of the Product of an Array 2 | 3 | Dificulty: Easy 4 | 5 | Problem: https://leetcode.com/problems/sign-of-the-product-of-an-array/ -------------------------------------------------------------------------------- /Leetcode/Simplify Path/readme.md: -------------------------------------------------------------------------------- 1 | LeetCode Simplify Path https://leetcode.com/problems/simplify-path/ 2 | 3 | Difficulty : Medium 4 | -------------------------------------------------------------------------------- /Leetcode/Single Number/readme.md: -------------------------------------------------------------------------------- 1 | ## Single Number 2 | 3 | Difficulty: Easy 4 | 5 | Problem Link: https://leetcode.com/problems/single-number/ -------------------------------------------------------------------------------- /Leetcode/Single Number/solution.cpp: -------------------------------------------------------------------------------- 1 | // XOR Approach: 2 | // Initialize ans to 0 3 | // Iterate over the array and take XOR of the current element with ans 4 | // Use of 2 properties (1) x ^ x = 0 (2) x ^ 0 = x 5 | class Solution { 6 | public: 7 | int singleNumber(vector& nums) { 8 | int ans = 0; 9 | for (int num: nums) { 10 | ans = ans ^ num; 11 | } 12 | return ans; 13 | } 14 | }; -------------------------------------------------------------------------------- /Leetcode/Single element in a sorted array/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Medium 2 | 3 | Problem Link: https://leetcode.com/problems/single-element-in-a-sorted-array/ 4 | -------------------------------------------------------------------------------- /Leetcode/Sort Array By Parity/Solution.cpp: -------------------------------------------------------------------------------- 1 | vector sortArrayByParity(vector& nums) { 2 | int begin = 0, end = nums.size()-1; 3 | if(nums.size()==1) return nums; 4 | while(begin<=end) 5 | { 6 | //start from the beginning and end 7 | //if it is even then increment and if it odd then decrement. 8 | //then swap it until begin<=end 9 | if(nums[begin]%2==0) begin++; 10 | if(nums[end]%2==1) end--; 11 | if(begin<=end) 12 | { 13 | swap(nums[begin],nums[end]); 14 | } 15 | } 16 | return nums; 17 | 18 | } -------------------------------------------------------------------------------- /Leetcode/Sort Array By Parity/readme.md: -------------------------------------------------------------------------------- 1 | Problem link:https://leetcode.com/problems/sort-array-by-parity/ -------------------------------------------------------------------------------- /Leetcode/Sort colors/Readme.md: -------------------------------------------------------------------------------- 1 | Difficulty:- Medium 2 | 3 | https://leetcode.com/problems/sort-colors/ -------------------------------------------------------------------------------- /Leetcode/Sort the Matrix Diagonally/Readme.md: -------------------------------------------------------------------------------- 1 | ### Sort the Matrix Diagonally 2 | 3 | **Link**: https://leetcode.com/problems/sort-the-matrix-diagonally/ 4 | **Difficulty**: Medium 5 | -------------------------------------------------------------------------------- /Leetcode/Spiral Matrix/readme.md: -------------------------------------------------------------------------------- 1 | # Spiral Matrix 2 | 3 | Difficulty : Medium 4 | 5 | Problem link : https://leetcode.com/problems/spiral-matrix/ 6 | -------------------------------------------------------------------------------- /Leetcode/Split Array Largest Sum/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Hard 2 | Link to the problem: https://leetcode.com/problems/split-array-largest-sum/ -------------------------------------------------------------------------------- /Leetcode/Split Linked List in Parts/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | 3 | https://leetcode.com/problems/split-linked-list-in-parts/ 4 | -------------------------------------------------------------------------------- /Leetcode/Sqrt-x/Readme.md: -------------------------------------------------------------------------------- 1 | ## Sqrt(x) 2 | 3 | Difficulty: Easy 4 | 5 | Problem: https://leetcode.com/problems/sqrtx/ 6 | -------------------------------------------------------------------------------- /Leetcode/Sqrt-x/Solution.cpp: -------------------------------------------------------------------------------- 1 | //This solution uses trial and error to find the square root of a number. 2 | //It basically multiplies each number in the number system( except negatives) 3 | //with themselves until the required square is obtained. 4 | 5 | 6 | class Solution 7 | { 8 | public: 9 | int mySqrt(int x) 10 | { 11 | long r = 1; 12 | while (r * r <= x) 13 | r++; 14 | return r - 1; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /Leetcode/Sqrtx/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Easy 2 | Problem Link : https://leetcode.com/problems/sqrtx/ 3 | -------------------------------------------------------------------------------- /Leetcode/Sqrtx/solution.cpp: -------------------------------------------------------------------------------- 1 | /** Approach: We use long long int to avoid overflow. For searching a number binary search takes logn time so, I have used Binary search. **/ 2 | 3 | 4 | class Solution { 5 | public: 6 | int mySqrt(int x) { 7 | 8 | long long int lo = 1, hi = x, mid, ans; 9 | while(lo <= hi){ 10 | mid = lo + (hi - lo)/2; 11 | if(mid * mid == x){ 12 | return mid; 13 | }else if(mid * mid > x){ 14 | hi = mid-1; 15 | }else{ 16 | lo = mid+1; 17 | } 18 | } 19 | return hi; 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /Leetcode/Strong Password Checker/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/strong-password-checker/ 2 | -------------------------------------------------------------------------------- /Leetcode/Subarray Sum Equals k/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Medium 2 | Question Link: https://leetcode.com/problems/subarray-sum-equals-k/ 3 | -------------------------------------------------------------------------------- /Leetcode/Subarray Sums Divisible by K/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Medium 2 | Link to the problem: https://leetcode.com/problems/subarray-sums-divisible-by-k/ -------------------------------------------------------------------------------- /Leetcode/Subarrays with K Different Integers/readme.md: -------------------------------------------------------------------------------- 1 | Problem : Subarrays with K Different Integers 2 | Link : https://leetcode.com/problems/subarrays-with-k-different-integers/ 3 | Difficulty : Hard -------------------------------------------------------------------------------- /Leetcode/Subtract the Product and Sum of Digits of an Integer/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/ 2 | -------------------------------------------------------------------------------- /Leetcode/Subtract the Product and Sum of Digits of an Integer/solution.java: -------------------------------------------------------------------------------- 1 | // package Hack-CP-DSA.Leetcode.Subtract the Product and Sum of Digits of an Integer; 2 | 3 | public class Solution { 4 | public int subtractProductAndSum(int n) { 5 | int product = 1; 6 | int sum = 0; 7 | while(n > 0) { // loop till input>0 8 | int temp = n % 10; // module for getting remainder 9 | n /= 10; // divide to get quotent 10 | product *= temp; // to get product of remainder 11 | sum += temp; // to get sum of quotent 12 | } 13 | return product - sum; // to return subtraction of product & sum. 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Leetcode/Swim in rising water/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Hard 2 | 3 | Problem link: https://leetcode.com/problems/swim-in-rising-water -------------------------------------------------------------------------------- /Leetcode/Symmetric Tree/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Easy Problem Link: https://leetcode.com/problems/symmetric-tree/ -------------------------------------------------------------------------------- /Leetcode/TaskScheduler/README.md: -------------------------------------------------------------------------------- 1 | ## Leetcode: Task Scheduler ## 2 | Difficulty : Medium 3 | Link: https://leetcode.com/problems/task-scheduler/ 4 | 5 | -------------------------------------------------------------------------------- /Leetcode/The Skyline Problem/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Hard 2 | 3 | Link : https://leetcode.com/problems/the-skyline-problem/ -------------------------------------------------------------------------------- /Leetcode/Transform to Chessboard/readme.md: -------------------------------------------------------------------------------- 1 | ## Leetcode: Transform to Chessboard 2 | 3 | Difficulty : Hard 4 | Link:https://leetcode.com/problems/transform-to-chessboard/ 5 | -------------------------------------------------------------------------------- /Leetcode/Trapping rain water/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/trapping-rain-water/ 2 | -------------------------------------------------------------------------------- /Leetcode/Triangle/readme.md: -------------------------------------------------------------------------------- 1 | + Difficulty: Medium 2 | + Problem Link: https://leetcode.com/problems/triangle/ -------------------------------------------------------------------------------- /Leetcode/Truncate Sentence/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/truncate-sentence/ -------------------------------------------------------------------------------- /Leetcode/Truncate Sentence/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string truncateSentence(string s, int k) { 4 | // sp is counter for number of spaces 5 | int i,sp=0; 6 | for(i=0;i (target - arr[i]) : index. 5 | Step 2: 6 | - Iterate to the array. 7 | Step 3: 8 | - If the value present in the dict --> return the value and the array value index. 9 | """ 10 | class Solution: 11 | def twoSum(self, nums, target): 12 | d = {} 13 | for index , l in enumerate(nums): 14 | d[(target - l)] = index 15 | print(d) 16 | for index , l in enumerate(nums): 17 | if l in d and index != d[l]: 18 | 19 | 20 | return [index , d[l]] -------------------------------------------------------------------------------- /Leetcode/Unique Paths II/readme.md: -------------------------------------------------------------------------------- 1 | + Difficulty: Medium 2 | 3 | + Problem Link: https://leetcode.com/problems/unique-paths-ii/ -------------------------------------------------------------------------------- /Leetcode/Unique Paths/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty : Medium 2 | 3 | Link : https://leetcode.com/problems/unique-paths/ -------------------------------------------------------------------------------- /Leetcode/Unqiue Binary Search Trees/readme.md: -------------------------------------------------------------------------------- 1 | + Difficulty: Medium 2 | + Problem Link: https://leetcode.com/problems/unique-binary-search-trees/ -------------------------------------------------------------------------------- /Leetcode/Valid Anagram/README.md: -------------------------------------------------------------------------------- 1 | Link : https://leetcode.com/problems/valid-anagram/ 2 | -------------------------------------------------------------------------------- /Leetcode/Valid Mountain Array/readme.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | Problem Link - https://leetcode.com/problems/valid-mountain-array/ 4 | 5 | Difficulty:- Easy -------------------------------------------------------------------------------- /Leetcode/Valid Mountain Array/solution.py: -------------------------------------------------------------------------------- 1 | def validMountainArray(arr): 2 | i = 0 3 | 4 | # to check whether values of array are in increasing order 5 | while i < len(arr) and i+1 < len(arr) and arr[i] < arr[i+1]: 6 | i += 1 7 | 8 | # i == 0 means there's no increasing sequence 9 | # i+1 >= len(arr) means the whole array is in increasing order 10 | if i == 0 or i + 1 >= len(arr): 11 | return False 12 | 13 | # to check whether values of array are in decreasing order 14 | while(i < len(arr) and i+1 < len(arr)): 15 | if arr[i] <= arr[i+1]: 16 | return False 17 | i += 1 18 | 19 | return True 20 | 21 | 22 | print(validMountainArray([0, 3, 2, 1])) 23 | -------------------------------------------------------------------------------- /Leetcode/Valid parentheses/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty:- Easy 2 | 3 | https://leetcode.com/problems/valid-parentheses/ -------------------------------------------------------------------------------- /Leetcode/Validate Binary Search Tree/readme.md: -------------------------------------------------------------------------------- 1 | ## Validate Binary Search Tree 2 | 3 | Difficulty: Medium 4 | 5 | Problem Link: https://leetcode.com/problems/validate-binary-search-tree/ -------------------------------------------------------------------------------- /Leetcode/Word Search/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty: Medium 2 | 3 | Question Link:[Word Search](https://leetcode.com/problems/word-search/) -------------------------------------------------------------------------------- /Leetcode/XOR Queries of a Subarray/readme.md: -------------------------------------------------------------------------------- 1 | Problem: XOR Queries of a Subarray , https://leetcode.com/problems/xor-queries-of-a-subarray/ 2 | 3 | Difficulty level : Medium -------------------------------------------------------------------------------- /Leetcode/XOR operation in an array/readme.md: -------------------------------------------------------------------------------- 1 | Difficulty:- Easy 2 | 3 | https://leetcode.com/problems/xor-operation-in-an-array/ 4 | -------------------------------------------------------------------------------- /Leetcode/XOR operation in an array/solution.cpp: -------------------------------------------------------------------------------- 1 | //XOR - returns 1 if two bits are different 2 | //'^' - Bitwise XOR 3 | 4 | //2^i = i << 1 5 | //let i = 2, 2 left shift by 1 = 4, 2^2 = 4 6 | //With every loop, value of 'ans' is updated 7 | 8 | class Solution { 9 | public: 10 | int xorOperation(int n, int start) { 11 | 12 | int ans =0; 13 | for(int i=0;i 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/subsets/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/subsets/ -------------------------------------------------------------------------------- /Leetcode/verify an alien dictionary/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/verifying-an-alien-dictionary/ -------------------------------------------------------------------------------- /Leetcode/verify an alien dictionary/solution.cpp: -------------------------------------------------------------------------------- 1 | unordered_map mp; 2 | bool isAlienSorted(vector& words, string order) { 3 | for(int i = 0; i < size(order); i++) mp[order[i]] = i; // mapping letter to its corresponding index in order 4 | for(int i = 0; i < size(words) - 1; i++) 5 | if(!checkOrder(words[i], words[i + 1])) return false; 6 | return true; 7 | } 8 | // checking if two words are lexicographically sorted 9 | bool checkOrder(string& a, string& b){ 10 | int i = -1; 11 | while(++i < size(a) && i < size(b)) 12 | if(mp[a[i]] != mp[b[i]]) return mp[a[i]] < mp[b[i]]; 13 | return size(a) <= size(b); 14 | } -------------------------------------------------------------------------------- /URIOnlineJudge/Carnaval/readme.md: -------------------------------------------------------------------------------- 1 | Problem: Carnaval 2 | 3 | Level: **Ad Hoc** 4 | 5 | Problem Link: https://www.urionlinejudge.com.br/judge/en/problems/view/2418 -------------------------------------------------------------------------------- /URIOnlineJudge/Dancing sentence/readme.md: -------------------------------------------------------------------------------- 1 | Problem: Dancing Sentence 2 | 3 | Level: **Strings** 4 | 5 | Problem Link: https://www.urionlinejudge.com.br/judge/en/problems/view/1234 -------------------------------------------------------------------------------- /URIOnlineJudge/Maesters Map/readme.md: -------------------------------------------------------------------------------- 1 | Problem: Maester's Map 2 | 3 | Level: **Graph** 4 | 5 | Problem Link: https://www.urionlinejudge.com.br/judge/en/problems/view/1855 -------------------------------------------------------------------------------- /URIOnlineJudge/Sorting Santa List of Children/Readme.md: -------------------------------------------------------------------------------- 1 | >Problem: Sorting Santa List of Children 2 | > 3 | >Level: **Ad Hoc** 4 | > 5 | >Problem Link: https://www.urionlinejudge.com.br/judge/en/problems/view/2479 -------------------------------------------------------------------------------- /URIOnlineJudge/The change/readme.md: -------------------------------------------------------------------------------- 1 | Problem: The change 2 | 3 | Level: **Begginer** 4 | 5 | Problem Link: https://www.urionlinejudge.com.br/judge/en/problems/view/2685 -------------------------------------------------------------------------------- /URIOnlineJudge/Triangle/Readme.md: -------------------------------------------------------------------------------- 1 | >Problem: Triangle 2 | > 3 | >Level: **Beginner** 4 | > 5 | >Problem Link: https://www.urionlinejudge.com.br/judge/en/problems/view/1043 -------------------------------------------------------------------------------- /URIOnlineJudge/Triangle/solution.py: -------------------------------------------------------------------------------- 1 | def solution(): 2 | # taking asked inputs 3 | A, B, C = map(float, input().split()) 4 | 5 | #check triangle inequality conditions 6 | if (A + B) > C and (A + C) > B and (B + C) > A: 7 | perimeter = (A + B + C) 8 | print(f"Perimetro = {perimeter:0.1f}") 9 | else: 10 | area = 0.5 * (A + B) * C 11 | print(f"Area = {area:0.1f}") 12 | 13 | 14 | if __name__ == '__main__': 15 | solution() --------------------------------------------------------------------------------