MCPcopy Create free account

hub / github.com/devparthgarg/Data-Structures-and-Algorithms / functions

Functions1,161 in github.com/devparthgarg/Data-Structures-and-Algorithms

↓ 1 callersFunctionisZero
trick : using prefix sum + hashing
09. Hashing/08 Subarray with Zero Sum/08b SubArray with Zero Sum.cpp:5
↓ 1 callersFunctionisZero
subarray means contigous elements
09. Hashing/08 Subarray with Zero Sum/08a SubArray with Zero Sum.cpp:5
↓ 1 callersFunctioniterativeInorder
Time: O(n) Space: O(n)
15. Binary Tree/25 Iterative Inorder Traversal/24.cpp:21
↓ 1 callersFunctionjosephus
04. Recursion/14 Josephus Problem/14 Josephus Problem.cpp:4
↓ 1 callersFunctionkClosest
17. Heaps/14 K Closest Elements/14b K-Closest Elements.cpp:4
↓ 1 callersFunctionkClosest
17. Heaps/14 K Closest Elements/14a K-Closest Elements.cpp:9
↓ 1 callersFunctionkLargest
17. Heaps/13 K Largest Element/13b K-Largest Element.cpp:4
↓ 1 callersFunctionkLargest
17. Heaps/13 K Largest Element/13a K-Largest Element.cpp:4
↓ 1 callersFunctionkSorted
17. Heaps/11 Sort K Sorted Array/11b Sort K-Sorted Array.cpp:10
↓ 1 callersFunctionkSorted
17. Heaps/11 Sort K Sorted Array/11a Sort K-Sorted Array.cpp:10
↓ 1 callersFunctionlargest
05. Arrays/05 Second Largest Element/05a Second Largest Element.cpp:4
↓ 1 callersFunctionlargest
Time: O(n)
05. Arrays/04 Largest Element/04 Largest Element.cpp:5
↓ 1 callersFunctionlastOccurrence
06. Searching/04 Count Occurrences/04b.cpp:38
↓ 1 callersFunctionlastOccurrence
time: O(logn) space: O(logn)
06. Searching/03 Index of Last Occurrence/03c index of last occurrence.cpp:6
↓ 1 callersFunctionlastOccurrence
time: O(n)
06. Searching/03 Index of Last Occurrence/03a index of last occurrence.cpp:5
↓ 1 callersFunctionlastOccurrence
time: O(logn)
06. Searching/03 Index of Last Occurrence/03b index of last occurrence.cpp:5
↓ 1 callersFunctionlcs
Tabulation
21. Dynamic Programming/03 Longest Common Subsequence/03c Longest Common Subsequence.cpp:5
↓ 1 callersFunctionlcs
Memoization
21. Dynamic Programming/03 Longest Common Subsequence/03b Longest Common Subsequence.cpp:7
↓ 1 callersFunctionlcs
Recursive
21. Dynamic Programming/03 Longest Common Subsequence/03a Longest Common Subsequence.cpp:13
↓ 1 callersFunctionleaders
Time: O(n)
05. Arrays/12 Leaders in Array/12b Leaders in Array.cpp:10
↓ 1 callersFunctionleaders
Time: O(n^2)
05. Arrays/12 Leaders in Array/12a Leaders in Array.cpp:9
↓ 1 callersFunctionleftMostNonRepeating
efficient approach
10. Strings/12 Leftmost Non Repeating Character/12b Leftmost Non Repeating Character.cpp:5
↓ 1 callersFunctionleftMostNonRepeating
naive approach
10. Strings/12 Leftmost Non Repeating Character/12a Leftmost Non Repeating Character.cpp:5
↓ 1 callersFunctionleftMostRepeating
10. Strings/11 Leftmost Repeating Character/11b Leftmost Repeating Character.cpp:7
↓ 1 callersFunctionleftMostRepeating
10. Strings/11 Leftmost Repeating Character/11a Leftmost Repeating Character.cpp:7
↓ 1 callersFunctionleftView
15. Binary Tree/13 Left View of Binary Tree/13b.cpp:46
↓ 1 callersFunctionleftView
Time: O(N) Space: O(W); W:width of tree (Worst Case: W ~ N) print first node only at each level
15. Binary Tree/13 Left View of Binary Tree/13a.cpp:27
↓ 1 callersFunctionlevelOrder
Time: O(N) Space: O(N) when complete level is traversed,push NULL into queue
15. Binary Tree/10 Level Order Traversal Line by Line/10b.cpp:22
↓ 1 callersFunctionlevelOrder
Time: O(N*LogN) Space: O(logN)
15. Binary Tree/10 Level Order Traversal Line by Line/10a.cpp:49
↓ 1 callersFunctionlevelOrder
Time: O(N) Space: O(W); W:width of tree (Worst Case: W ~ N)
15. Binary Tree/10 Level Order Traversal Line by Line/10c.cpp:21
↓ 1 callersFunctionlevelOrder
15. Binary Tree/24 Serialize and Deserialize Binary Tree/24.cpp:62
↓ 1 callersFunctionlevelOrder
Time: O(N) Space: O(W)
15. Binary Tree/09 Level Order Traversal/09b.cpp:21
↓ 1 callersFunctionlevelOrder
Time: O(N*LogN) Space: O(logN)
15. Binary Tree/09 Level Order Traversal/09a.cpp:49
↓ 1 callersFunctionlexiographicRank
Time: O(n!) Space: O(n)
10. Strings/17 Lexiographic Rank of a String/17a Lexiographic Rank of a String.cpp:6
↓ 1 callersFunctionlinearSearch
Time: O(n) for unsorted array Time: O(logn) for sorted array (Binary Search)
05. Arrays/01 Linear Search/01 Linear Search.cpp:6
↓ 1 callersFunctionlomutoPartition
pivot given by user
07. Sorting/13 Lomuto Partition/13b Lomuto Partitioning.cpp:5
↓ 1 callersFunctionlomutoPartition
considering last element is the pivot element
07. Sorting/13 Lomuto Partition/13a Lomuto Partitioning.cpp:5
↓ 1 callersFunctionlomutoPartition
07. Sorting/15 Quick Sort/15b Quick Sort using Lomuto Partition.cpp:4
↓ 1 callersFunctionlongest01
09. Hashing/11 Longest Subarray with Equal 0s and 1s/11a Longest SubArray with equal 0s and 1s.cpp:4
↓ 1 callersFunctionlongest01
trick : replace all 0s with -1 and use function longest subarray with sum equals 0
09. Hashing/11 Longest Subarray with Equal 0s and 1s/11b Longest SubArray with equal 0s and 1s.cpp:5
↓ 1 callersFunctionlongestCommonSpan
09. Hashing/12 Longest Common Span with Same Sum in Binary Array/12a Longest Common Span with Same Sum in Binary Array.cpp:4
↓ 1 callersFunctionlongestConsecutiveSubsequence
09. Hashing/13 Longest Common Subsequence/13a Longest Consecutive SubSequence.cpp:4
↓ 1 callersFunctionlongestSubArray
09. Hashing/10 Longest Subarray with Given Sum/10a Longest SubArray with given Sum.cpp:4
↓ 1 callersFunctionlongestSubArray
09. Hashing/10 Longest Subarray with Given Sum/10b Longest SubArray with given Sum.cpp:4
↓ 1 callersFunctionlongestSubstring
Time: O(n) Space: O(n)
10. Strings/18 Longest Substring with Distinct Characters/18c Longest Substring with Distinct Characters.cpp:6
↓ 1 callersFunctionlongestSubstring
Time: O(n^2) Space: O(n)
10. Strings/18 Longest Substring with Distinct Characters/18b Longest Substring with Distinct Characters.cpp:6
↓ 1 callersFunctionlongestSubstring
Time: O(n^3) Space: O(n)
10. Strings/18 Longest Substring with Distinct Characters/18a Longest Substring with Distinct Characters.cpp:13
↓ 1 callersFunctionmajorityElement
time: O(n*n)
05. Arrays/21 Majority Element/21a Majority Element.cpp:5
↓ 1 callersFunctionmajorityElement
Moore's Voting Algorithm time: O(n)
05. Arrays/21 Majority Element/21b Majority Element.cpp:6
↓ 1 callersFunctionmatching
12. Stacks/04 Balanced Parentheses/04 Balanced Parentheses.cpp:4
↓ 1 callersFunctionmaxAppearing
time: O(n*n) space: O(n)
05. Arrays/28 Find Maximum Occurring Element in Ranges/28a Find Maximum Occurring Element in Ranges.cpp:11
↓ 1 callersFunctionmaxAppearing
time: O(n) space: O(n)
05. Arrays/28 Find Maximum Occurring Element in Ranges/28b Find Maximum Occurring Element in Ranges.cpp:11
↓ 1 callersFunctionmaxCircularSubArraySum
time: O(n)
05. Arrays/20 Max Circular Subarray Sum/20b Max Circular Subarray Sum.cpp:23
↓ 1 callersFunctionmaxCircularSubArraySum
time: O(n*n)
05. Arrays/20 Max Circular Subarray Sum/20a Max Circular Subarray Sum.cpp:17
↓ 1 callersFunctionmaxConsecutive1
time: O(n)
05. Arrays/17 Maximum Consecutive 1s/17 Maximum Consecutive 1.cpp:5
↓ 1 callersFunctionmaxDiff
time: O(n)
05. Arrays/13 Maximum Difference/13b Maximum Difference.cpp:5
↓ 1 callersFunctionmaxDiff
time: O(n*n)
05. Arrays/13 Maximum Difference/13a Maximum Difference.cpp:5
↓ 1 callersFunctionmaxEqualLength
time: O(n) space: O(n)
05. Arrays/31 Max Length of Subarray with Equal 0s and 1s/31 Max Length of Subarray with Equal 0s and 1s.cpp:10
↓ 1 callersFunctionmaxItems
17. Heaps/12 Purchasing Maximum Items/12a Purchasing Maximum Items.cpp:4
↓ 1 callersFunctionmaxItems
Efficient Solution (better soln. than previous one in most of the cases)
17. Heaps/12 Purchasing Maximum Items/12b Purchasing Maximum Items.cpp:5
↓ 1 callersFunctionmaxKSum
Sliding Window: sliding a window of size k time: O(n)
05. Arrays/23 Max Sum of K Consecutive Element/23b Max Sum of K Consecutive elements.cpp:6
↓ 1 callersFunctionmaxKSum
time: O(n*n)
05. Arrays/23 Max Sum of K Consecutive Element/23a Max Sum of K Consecutive elements.cpp:10
↓ 1 callersFunctionmaxKSum
Sliding Window: sliding a window of size k time: O(n)
05. Arrays/24 Find Subarray with Given Sum/24b Check Subarray with Given Sum.cpp:6
↓ 1 callersFunctionmaxLengthEvenOddSubArray
time: O(n)
05. Arrays/19 Max Length Even Odd Subarray/19 Max Length Even Odd SubArray.cpp:5
↓ 1 callersFunctionmaxOfSubarrays
Print all maximum in size of subarray k
14. Deque/05 Maximum of all Subarrays of size K/05a.cpp:5
↓ 1 callersFunctionmaxOfSubarrays
Time: O(N) space: O(K)
14. Deque/05 Maximum of all Subarrays of size K/05b.cpp:15
↓ 1 callersFunctionmaxPieces
04. Recursion/11 Rope Cutting Problem/11 Rope Cutting Problem.cpp:7
↓ 1 callersFunctionmaxSubArraySum
time: O(n*n)
05. Arrays/18 Maximum Subarray Sum/18a Maximum Sub Array Sum.cpp:5
↓ 1 callersFunctionmaxSubarraySum
Kadane's Algo time: O(n)
05. Arrays/18 Maximum Subarray Sum/18b Maximum Sub Array Sum.cpp:6
↓ 1 callersFunctionmaxSum
Recursion
21. Dynamic Programming/06 Maximum Sum with no 2 Consecutive/06a Maximum Sum with no 2 Consecutive.cpp:5
↓ 1 callersFunctionmaxSum
Memoization
21. Dynamic Programming/06 Maximum Sum with no 2 Consecutive/06b Maximum Sum with no 2 Consecutive.cpp:5
↓ 1 callersFunctionmaxSum
Tabulation
21. Dynamic Programming/06 Maximum Sum with no 2 Consecutive/06c Maximum Sum with no 2 Consecutive.cpp:5
↓ 1 callersFunctionmaxWidth
Time: O(N) Space: O(W) W:width of tree
15. Binary Tree/16 Maximum Width of Binary Tree/16.cpp:21
↓ 1 callersFunctionmaximum
Time: O(N) Space: O(H);
15. Binary Tree/12 Maximum in Binary Tree/12b.cpp:21
↓ 1 callersFunctionmaximum
Time: O(N) Space: O(W)
15. Binary Tree/12 Maximum in Binary Tree/12a.cpp:21
↓ 1 callersFunctionmedian
06. Searching/15 Median of Two Sorted Arrays/15b.cpp:4
↓ 1 callersFunctionmedian
06. Searching/15 Median of Two Sorted Arrays/15a.cpp:4
↓ 1 callersFunctionmedian
Assumptions : 1.odd sized arrays 2.all distinct elements*/
08. Matrix/08 Median of Row wise Sorted Matrix/08b Median of Row Wise Sorted Matrix.cpp:7
↓ 1 callersFunctionmedian
Assumptions : 1.odd sized arrays 2.all distinct elements */
08. Matrix/08 Median of Row wise Sorted Matrix/08a Median of Row Wise Sorted Matrix.cpp:9
↓ 1 callersFunctionmerge
Time: O(N) Space: O(1)
11. Linked List/40 Merge Two Sorted LL/40 Merge Two Sorted LL.cpp:19
↓ 1 callersFunctionmerge
07. Sorting/07 Merge Sort/07b Merge Function of Merge Sort.cpp:4
↓ 1 callersFunctionmerge
07. Sorting/07 Merge Sort/07c Merge Sort.cpp:4
↓ 1 callersFunctionmerge
07. Sorting/06 Merge Two Sorted Arrays/06b Merge Two Sorted Arrays.cpp:4
↓ 1 callersFunctionmerge
07. Sorting/06 Merge Two Sorted Arrays/06a Merge Two Sorted Arrays.cpp:4
↓ 1 callersFunctionmergeKSorted
17. Heaps/15 Merge K Sorted Arrays/15a Merge K Sorted Arrays.cpp:4
↓ 1 callersFunctionmergeSort
07. Sorting/07 Merge Sort/07c Merge Sort.cpp:55
↓ 1 callersFunctionmiddle
Time: O(N) Space: O(1)
11. Linked List/25 Middle Of Linked List/25b Middle Of Linked List.cpp:19
↓ 1 callersFunctionmiddle
Time: O(N) Space: O(1)
11. Linked List/25 Middle Of Linked List/25a Middle Of Linked List.cpp:19
↓ 1 callersFunctionmin
21. Dynamic Programming/05 Edit Distance/05b Edit Distance.cpp:6
↓ 1 callersFunctionminCoins
time: O(n*logn) space: O(1)
19. Greedy Algorithms/01 Minimum Coins/01 Minimum Coins.cpp:6
↓ 1 callersFunctionminDif
07. Sorting/20 Minimum Difference in Array/20a Minimum Difference in Array.cpp:4
↓ 1 callersFunctionminDif
07. Sorting/20 Minimum Difference in Array/20b Minimum Difference in Array.cpp:4
↓ 1 callersFunctionminFlips
time: O(n) (one traversal)
05. Arrays/22 Minimum Consecutive Flips/22b Minimum Flips to make Array same.cpp:10
↓ 1 callersFunctionminFlips
time: O(n) (two traversals)
05. Arrays/22 Minimum Consecutive Flips/22a Minimum Flips to make Array same.cpp:10
↓ 1 callersFunctionmini
21. Dynamic Programming/05 Edit Distance/05c Edit Distance.cpp:4
↓ 1 callersFunctionmissing
trick 1 : xor of same numbers gives zero trick 2 : xor of zero with any number returns original number
03. Bit Manipulation/05 One Odd Occurring/Bonus Question.cpp:8
↓ 1 callersFunctionmoveZeros
Time: O(n^2)
05. Arrays/09 Move Zeros to End/09a Move Zero to End.cpp:5
↓ 1 callersFunctionmoveZeros
Time: O(n)
05. Arrays/09 Move Zeros to End/09b Move Zero to End.cpp:5
↓ 1 callersFunctionnaivePartition
07. Sorting/12 Naive Partition/12 Naive Partitioning.cpp:4
↓ 1 callersFunctionnextGreater
time: O(n) space: O(n)
12. Stacks/09 Next Greater Element/09b Next Greater Element.cpp:6
← previousnext →301–400 of 1,161, ranked by callers