Skip to main content

Medium ✔

  1. Longest Substring Without Repeating Characters
    1. 31 March, 2026: 00.04.58 ✔
  2. Max Consecutive Ones III
    1. 01 April, 2026: 00.02.44 ✔
  3. Fruit Into Baskets
    1. 01 April, 2026: 00.05.35 ✔
  4. Longest Repeating Character Replacement
    1. 02 April, 2026: 00.17.45 ❌
      • Failed at implementation
        • The desire case is longest sequence - maximum frequency should be greater than k
  5. Binary Subarrays With Sum
    1. 31 March, 2026: 00.12.07 ❌
      • Failed at edge cases
        • Count leading zeros
        • Traditional sliding window fail
        • Sliding window works best when:
          • The window sum behaves monotonically (only increases when expanding, decreases when shrinking)
          • You can adjust the window deterministically based on comparison
        • When you expand the window:
          • Adding 1 increases sum
          • Adding 0 does NOT change sum
        • Method 1: Prefix Sum + HashMap
          current_sum - previous_sum = goal
        • Method 2: Modified Sliding Window
          exact(goal) = atMost(goal) - atMost(goal - 1)
          Now define: atMost(k) = number of subarrays with sum ≤ k
          This works because:
          • Sliding window can handle ≤ k
          • It avoids the “multiple zero ambiguity”
  6. Count number of Nice subarrays
    1. 31 March, 2026: 00.12.07 ❌
      • Failed at edge cases
        • Count leading even numbers (for subarray start positions)
  7. Number of Substrings Containing All Three Characters
    1. 31 March, 2026: 00.22.54 ❌
      • Expand if you don't have the answer
      • Shrink if you have the answer
      • All substrings starting at left to right are valid
  8. Maximum Points You Can Obtain from Cards
    1. 31 March, 2026: 00.34.33 ❌
      • Failed at implementation
        • In one step, you can take one card from the beginning or from the end of the row.
          take k from left, 0 from right
          take n-1 from left, 1 from right
          take n-2 from left, 2 from right
          take k-3 from left, 3 from right
        • Only the kth item from the begin and end matter