Day 54 of #100DaysOfDSA ๐
Solved Pair Sum Problem on a sorted ArrayList using
๐ Two Pointer Approach
โก O(n) time | O(1) space
Simple logic, powerful optimization ๐ช
#DSAWithJava#TwoPointers#problemSolving
ALT โ ๐ Time & Space Complexity
โ Time Complexity: O(M log M M)
Sorting/grouping meetings by time โ log M
BFS visits each meeting edge once
๐ซ Space Complexity: O(N M)
knowsSecret[] for people and Temporary graph per time slot
ALT โ ๐ Time & Space Complexity
โ T.C: O(26 * n) โ O(n)
Because:
You iterate over all unique letters (max 26)
For each, you scan the string twice โ 26 ร n
๐ซ S.C: O(26) โ O(1)
Because:
Set of unique letters = max 26
Middle set also max 26
โ Constant extra space
โ ๐ Time & Space Complexity ::
โ T.C: O(n log n)
Sorting the intervals dominates the complexity.
Greedy traversal is O(n).
๐ซ S.C: O(1)
Only a few integer variables used โ constant extra space.
#DSAWithJava#DSA#problemsolving