MCPcopy Create free account

hub / github.com/BlakeBrown/HackerRank-Solutions / functions

Functions371 in github.com/BlakeBrown/HackerRank-Solutions

Functionmain
Main algorithm: Use modulo to figure out which indices we need to print without actually rotating the array.
Algorithms/Warmup/Circular Array Rotation.cpp:10
Functionmain
Algorithms/Strings/Make it Anagram.cpp:9
Functionmain
Algorithms/Strings/Pangrams.cpp:9
Functionmain
Algorithms/Strings/separate-the-numbers.cpp:32
Functionmain
Algorithms/Strings/Gem Stones.cpp:9
Functionmain
Question asks us to find the largest common subsequence between two strings (note: different than largest substring!) Great explanation of a DP (dynam
Algorithms/Strings/Common Child (largest subsequence).cpp:10
Functionmain
Algorithms/Strings/Sherlock and Anagrams.cpp:11
Functionmain
Finds the next largest lexographical permutation of a string (ex. dkhc -> hcdk) Explanation: http://www.nayuki.io/page/next-lexicographical-permutatio
Algorithms/Strings/Bigger is Greater.cpp:11
Functionmain
Algorithms/Strings/Funny String.cpp:9
Functionmain
Algorithms/Dynamic Programming/Candies - O(n) solution.cpp:9
Functionmain
Algorithms/Dynamic Programming/Red John is Back.cpp:9
Functionmain
Solution 2: Check candies in order of increasing rating, runs in O(nlogn)
Algorithms/Dynamic Programming/Candies - O(nlogn) solution.cpp:5
Functionmain
Lastly, here's a great video describing this approach: https://www.youtube.com/watch?v=NnD96abizww
Algorithms/Dynamic Programming/Longest Common Subsequence.cpp:27
Functionmain
Very similar to the coin change problem, we want to know if we can build a number or not
Algorithms/Dynamic Programming/Knapsack.cpp:10
Functionmain
Algorithms/Dynamic Programming/Bricks Game.cpp:8
Functionmain
Algorithms/Dynamic Programming/Stock Maximize.cpp:8
Functionmain
Algorithms/Dynamic Programming/Longest Increasing Subsequence.cpp:29
Functionmain
Algorithms/Dynamic Programming/Equal - O(n) greedy.cpp:38
Functionmain
Algorithms/Dynamic Programming/The Coin Change Problem.cpp:11
Functionmain
Algorithms/Dynamic Programming/The Maximum Subarray.cpp:10
Functionmain
Algorithms/Dynamic Programming/Mr K Marsh.cpp:9
Functionmain
Algorithms/Searching/Missing Numbers.cpp:9
Functionmain
Algorithms/Searching/Gena Playing Hanoi.cpp:70
Functionmain
Algorithms/Searching/Connected Cell in a Grid.cpp:45
Functionmain
Algorithms/Searching/Maximize Sum.cpp:55
Functionmain
Algorithms/Searching/Ice Cream Parlor.cpp:16
Functionmain
Algorithms/Searching/Count Luck.cpp:63
Functionmain
Algorithms/Searching/Binary Search.cpp:25
Functionmain
Algorithms/Searching/Sherlock and Array.cpp:12
Functionmain
Algorithm: Maintain a list of pairs (t[i] + d[i], i+1), sort by the first value and output by second Runtime: O(nlogn) since we have to sort the list
Algorithms/Greedy/Jim and the Orders.cpp:6
Functionmain
Algorithm: Sort the first array lexicographically increasing, the second array lexicographically decreasing This will maximize the value of array1[i]
Algorithms/Greedy/Two Arrays.cpp:15
Functionmain
Algorithms/Greedy/Algorithmic Crush.cpp:10
Functionmain
Algorithms/Greedy/Largest Permutation.cpp:18
Functionmain
Algorithm: Sort each row lexicographically, then check if each of the columns are lexicographically sorted Runtime: O(n^2) -> O(nlogn) to sort every r
Algorithms/Greedy/Grid Challenge.cpp:10
Functionmain
Algorithms/Greedy/Goodland Electricity.cpp:10
Functionmain
Algorithm: Sort the toys by price, buy the cheapest toy each time until you run out of money
Algorithms/Greedy/Mark and Toys.cpp:10
Functionmain
Algorithms/Greedy/Luck Balance.cpp:9
Functionmain
Algorithms/Implementation/Kaprekar-Numbers.cpp:38
Functionmain
Algorithms/Implementation/Caeser Cipher.cpp:19
Functionmain
Algorithms/Implementation/Lisa's Workbook.cpp:9
Functionmain
While this solution works, there is a much more elegant solution I found after reading the editorial. If N is even, then we simply need to consider N
Algorithms/Implementation/Absolute Permutation.cpp:12
Functionmain
Algorithms/Implementation/Organizing Containers of Balls.cpp:3
Functionmain
Algorithms/Implementation/Equal Stacks.cpp:27
Functionmain
Algorithms/Implementation/Cavity Map.cpp:9
Functionmain
Algorithms/Implementation/Cut the Sticks.cpp:8
Functionmain
Main algorithm: in order to rotate the whole matrix, we'll just rotate one ring at a time We can do this in-place to achieve O(1) additional space com
Algorithms/Implementation/Matrix Layer Rotation (clockwise).cpp:10
Functionmain
Algorithms/Implementation/Sherlock and Squares.cpp:9
Functionmain
Algorithms/Implementation/Utopian_Tree.cpp:5
Functionmain
Algorithms/Implementation/Encryption.cpp:24
Functionmain
Main algorithm: in order to rotate the whole matrix, we'll just rotate one ring at a time We can do this in-place to achieve O(1) additional space com
Algorithms/Implementation/Matrix Layer Rotation (anti-clockwise).cpp:10
Functionmain
Brute force approach passes all test cases, however we could do this in O(n) time using a hashtable
Algorithms/Implementation/Divisible Sum Pairs.cpp:27
Functionmain
Algorithms/Implementation/Non-divisible Subset.cpp:17
Functionmain
Algorithms/Implementation/The Grid Search.cpp:8
Functionmain
Algorithms/Implementation/Repeated String.cpp:27
Functionmain
Algorithms/Implementation/Chocolate Feast.cpp:8
Functionmain
Algorithms/Implementation/Climbing_the_Leaderboard.cpp:8
Functionmain
Brute force approach passes all test cases, but as with most questions of this format we can do better using a hashtable to get O(n) instead of O(n^2)
Algorithms/Implementation/Minimum Distances.cpp:28
Functionmain
Algorithms/Implementation/Kangaroo.cpp:27
Functionmain
Algorithms/Implementation/Angry Professor.cpp:8
Functionmain
Algorithms/Implementation/Sherlock and the Beast.cpp:10
Functionmain
Algorithms/Graph Theory/Prim's MST - Special Subtree.cpp:20
Functionmain
Algorithms/Graph Theory/Even Tree.cpp:62
Functionmain
Algorithms/Graph Theory/Kruskal's MST - Really Special Subtree.cpp:71
Functionmain
Algorithms/Graph Theory/Roads in Hackerland.cpp:72
Functionmain
Algorithms/Graph Theory/Dijkstra's SSSP - Shortest Reach 2.cpp:99
Functionmain
Algorithms/Graph Theory/Floyd-Warshall APSP - City of Blinding Lights.cpp:14
Functionmain
Algorithms/Graph Theory/Breadth First Search - Shortest Reach.cpp:12
Functionmain
Tutorials/Cracking the Coding Interview/Hash Tables - Ransom Note.cpp:51
Functionmain
Tutorials/Cracking the Coding Interview/Heaps - Find the Median.cpp:27
Functionmain
Given two strings, finds the minimum number of character deletions required to make the two strings anagrams.
Tutorials/Cracking the Coding Interview/Strings - Making Anagrams.cpp:9
Functionmain
Tutorials/Cracking the Coding Interview/Queues - A Tale of Two Stacks.cpp:42
Functionmain
Tutorials/Cracking the Coding Interview/Stacks - Balanced Brackets.cpp:56
Functionmain
Tutorials/Cracking the Coding Interview/Arrays - Left Rotation.cpp:35
Functionmain
Count the # of different chars in each string
Contests/2016 - July World Codesprint/String Construction.cpp:27
Functionmain
Add the number of uppercase letters in s, add one
Contests/2016 - July World Codesprint/CamelCase.cpp:27
Functionmain
Contests/2016 - Booking.com Backend/Coupling Passions.cpp:26
Functionmain
Works in 70% of the test cases - almost!!!
Contests/2015 - GoDaddy Hackathon/Hexagonal War.cpp:10
Functionmain
A variation on nim where you move one stone from a pile of higher index to lower index each turn See "Nim (MIT notes)" in this folder for an AMAZING e
Contests/2016 - Game Theory/Day 2 - Nimble Game.cpp:11
Functionmain
Great explanation of how xor solves nim at: https://en.wikipedia.org/wiki/Nim
Contests/2016 - Game Theory/Day 2 - Nim Game.cpp:9
Functionmain
Another dp problem! :)
Contests/2016 - Game Theory/Day 1 - A Chessboard Game.cpp:9
Functionmain
Contests/2016 - Game Theory/Day 1 - Game of Stones.cpp:9
Functionmain
Contests/2016 - Game Theory/Day 2 - Misère Nim.cpp:11
Functionmain
Same as standard nim :) If your opponent adds any stones, just remove them
Contests/2016 - Game Theory/Day 2 - Poker Nim.cpp:10
Functionmain
Contests/2016 - Game Theory/Day 1 - Tower Breakers.cpp:9
Functionmain
Contests/2016 - Game Theory/Day 2 - Tower Breakers, Revisited.cpp:10
Functionmain
Contests/2016 - May World Codesprint/Compare the Triplets.cpp:27
Functionmain
Contests/2016 - May World Codesprint/Richie Rich.cpp:9
Functionmain
While this solution works, there is a much more elegant solution I found after reading the editorial. If N is even, then we simply need to consider N
Contests/2016 - May World Codesprint/Absolute Permutation.cpp:12
Functionmain
Currently not a working solution -> need to come back and fix this later
Contests/2016 - May World Codesprint/Beautiful Quadruples.cpp:27
Functionmain
Contests/2015 - Magic Lines September/Connected Cell in a Grid 1.cpp:29
Functionmain
Contests/2015 - Magic Lines September/Common Child 1.cpp:15
Functionmain
Given two strings, finds the minimum number of character deletions required to make the two strings anagrams.
Contests/2015 - Magic Lines September/Make It Anagram.cpp:9
Functionmain
Contests/2016 - June World Codesprint/Equal Stacks.cpp:27
Functionmain
Contests/2016 - June World Codesprint/A or B.cpp:74
Functionmain
Contests/2016 - June World Codesprint/Roads in Hackerland.cpp:72
Functionmain
Contests/2016 - June World Codesprint/Minimum Distances.cpp:27
Functionmain
Contests/2016 - BlackRock Codesprint/Currency Arbitrage.cpp:9
Functionmain
Contests/2016 - BlackRock Codesprint/Employee Stock Grants.cpp:12
Functionmain
Key to this question is that the even fibonacci numbers can be expressed as their own sequence with their own linear reccurence relation, which makes
Contests/Project Euler/002.cpp:10
Functionmain
Note: Could have used std::vector instead of std::map here!
Contests/Project Euler/004.cpp:12
← previousnext →201–300 of 371, ranked by callers