Question Bank
/

JavaScript Longest and Shortest Unique Substring: Two Approaches Quiz

JavaScript Longest and Shortest Unique Substring: Two Approaches Quiz

Two seeded approaches to find the longest and shortest unique substrings (restart-on-conflict and instrumented restart), plus two companions on a real sliding window and complexity analysis.

Question Bank
Hard
JavaScript
quiz
strings
sliding-window
interview-prep

417 views

2

Implement getMinMaxSubstrings(str) that returns the lengths and last-found-text of the longest and shortest substrings without repeating characters. Use a restart-on-conflict scan with a temporary index map.

Examples

Example 1:

Input: 'mwwegkwe'
Output: { min: { minLength: 1, substring: 'w' }, max: { maxLength: 4, substring: 'egkw' } }
Explanation: 'w' restarts the window early (length 1), and 'egkw' is the longest restart-bounded unique slice.

Example 2:

Input: 'bbbbb'
Output: { min: { minLength: 1, substring: 'b' }, max: { maxLength: 1, substring: 'b' } }
Explanation: Every character collides immediately, so every unique substring has length 1.

3 more questions, with full solutions and explanations, are available for premium members.

Upgrade to Premium