Campbell Ritchie wrote:Congratulations on both counts.
Tim Holloway wrote:I would get approval first. Taking time off that close to your hire date would generally be a cause for concern if they didn't know far enough in advance.
Good fortune, though. I got married on a Saturday and started a new job on Monday. Never got a honeymoon.
Liutauras Vilda wrote:Cowgratulations, your post has been published in CodeRanch's August 2020 journal.
Campbell Ritchie wrote:Why do you need these counters when you can use Set#size() instead? Please explain how your loop works; I don't understand the logic. I cannot however break your code. Why are you accepting null or empty Strings?
Piet Souris wrote:@Punit
well done, and have a cow!
Piet Souris wrote:
An extra challenge for you: can you extend your method such that it also gives that longest substring, and its starting index?
Campbell Ritchie wrote:But what about the values? What are you doing with the values? Hint: nothing. So why are you using a map? Why don't you use other data structures/types?
Campbell Ritchie wrote:You mean O(1) time complexity? There are other data structures giving O(1) time complexity too. And some maps run in O(logn) time complexity. That is for the put() method, at least.
Campbell Ritchie wrote:But what about the values? What are you doing with the values? Hint: nothing. So why are you using a map? Why don't you use other data structures/types?
Campbell Ritchie wrote:You mean O(1) time complexity? There are other data structures giving O(1) time complexity too. And some maps run in O(logn) time complexity. That is for the put() method, at least.
Liutauras Vilda wrote:
Is that what your string shortening achieves?
expected:
pwwkew
wwkew
wkew
kew
...
Liutauras Vilda wrote:
Punit Jain wrote:Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
Apart from somewhere incorrect logic what Campbell already mentioned to you, your solution doesn't seem to adhere to the requirements you posted. I've bolded that part.
Campbell Ritchie wrote:
Why did you say “map”? Anyway, that is an implementation detail, which shouldn't be included in the logic.Punit Jain wrote:Keep appending the character to the map as map keys.
Campbell Ritchie wrote:
You mean when you encounter a character already recorded.Punit Jain wrote:As soon as I reach to a character that's already added to the map . . .
Campbell Ritchie wrote:
Another implementation detail.Punit Jain wrote:a temp variable.
Campbell Ritchie wrote:
Please explain what you mean about removal? Why don't you simply start from the next character? What does line 21 do?Punit Jain wrote:. . . remove the already visited characters . . .
Campbell Ritchie wrote:I think you are shortening the text from its beginning wrongly.
Campbell Ritchie wrote:Have a possible solution, but I am keeping it hidden.
My JShell wrote:SubstringFinder.main( "abcabcbb", "bbbbb", "pwwkew");
Longest substring = “abc”; length = 3
Longest substring = “b”; length = 1
Longest substring = “wke”; length = 3