Opening your workspace…
Workspace/Coding room
Opening your workspace…
A wren sets the type for the brewery's winter broadside. She owns exactly one piece of type for each printable ASCII character, including one much-prized space. Given the line of text, find the longest stretch of consecutive characters she can set in a single pass without using any character twice. Return its length. Uppercase and lowercase letters have separate pieces of type. A blank string needs none.
"coffee"Output3The longest such substring is ‘cof’, which has three characters.
"abcaef"Output5‘bcaef’ has five characters and none of them repeats.
Grow a window to the right one character at a time. When the new character is already in the window, move the left edge to just after its earlier position.
Compare remembering a character's position with remembering a number's index.
Try this problem →Class C · Strings / StacksTry a string problem where order is tracked by a stack instead of a window.
Try this problem →Class C · Arrays / Two pointersBuild confidence with two moving indices on sorted inputs.
Try this problem →/** @param {string} text * @returns {number} */ function solve(text) { // Keep a window with no repeated characters. }
Tab inserts two spaces. Shift+Tab outdents. Use the arrow keys and Tab to choose a suggestion. Press Escape, then Tab, to leave the editor. Press Control or Command with apostrophe to run samples or with Enter to submit.
"coffee"3