Coding_Round_Solutions_Array_DP_String
Coding_Round_Solutions_Array_DP_String
1. Leaders in an Array
[OK] Problem:
An element is a leader if it is greater than or equal to all elements to its right.
[Idea] Approach:
- Traverse from right to left.
- Keep track of max so far.
[Explain] Explanation:
From the end, compare with maxRight. Result: [17, 5, 2]
[OK] Problem:
Count the number of ways to cover distance n using steps of 1, 2, or 3.
Coding Round Solutions - Java (Array, DP, String)
[Idea] Approach:
Dynamic Programming: dp[i] = dp[i-1] + dp[i-2] + dp[i-3]
[Explain] Explanation:
dp[4] = dp[3] + dp[2] + dp[1] = 4 + 2 + 1 = 7
[OK] Problem:
Find the longest substring without repeating characters.
[Idea] Approach:
Use sliding window with HashMap to track characters.
[Explain] Explanation:
Sliding window resizes on repeat. Final length = 3 ("abc")