Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Its bit difficult to my head get around this implementation since in the previou...

Nikhil Srivastava

Jan 12, 2022

Its bit difficult to my head get around this implementation since in the previous problems we have been adding the character to the map first.. I think having a pictorial representation would have helped a lot..

6

0

Comments
Comments
N
Nikhil Srivastava4 years ago

This is my approach after lot of debugs:

public class NoRepeatSubstring {

public static int findLongestSubstringLength(String str) { int maxLength = 0, windowStart = 0; HashMap subStringMap = new HashMap(); for (int windowEnd = 0; windowEnd < str.length(); windowEnd++...

H
Hamidou Diallo3 years ago

A simple implementation using a set instead of a hash in ruby:

def longest_substring_with_distinct_chars(word) window_start = 0 char_set = Set.new longest_substring = Float::MIN

(0..word.length - 1).each do |window_end| right_char = word[window_end]

while char_set.in...

M
Manthan 3 years ago

@Nikhil Srivastava

Your code wont work for something like 'dvdf' Because when dv are in the map, and you get d again, you set window start =windowEnd where v is removed,

On this page