Yahoo India Web Search

Search results

  1. Mar 16, 2012 · Algorithm: 1) Initialise an empty dictionary dct to check if any character already exists in the string. 2) cnt - to keep the count of substring without repeating characters. 3) l and r are the two pointers initialised to first index of the string. 4)loop through each char of the string.

  2. Mar 22, 2022 · The problems asks "given a string, find the longest non-repeating sub-string without repeating characters". I am a little stumped why returning my code is not working for the string "dvdf" for example. Here is my code :

  3. Apr 22, 2019 · Longest Substring Without Repeating Characters. Medium. Given a string, find the length of the longest substring without repeating characters. Example 1: Input: "abcabcbb". Output: 3. Explanation: The answer is "abc", with the length of 3. Example 2: Input: "bbbbb".

  4. Jul 12, 2022 · To store the maximum length of the non-repeated substring we need to maintain a variable which has to be updated at the end of each iteration. That's how it can be implemented: Set<Character> seen = new HashSet<>(); int left = 0; int maxSub = 0; for(int right = 0; right < str.length(); right++) {.

  5. Jun 13, 2013 · The captures will show up in between the pieces. This is way I just added the isCapture flag.) The function cuts out all the repeated characters, and returns the longest piece that where in between the repeated each set of repeated characters. >>> MaximumSubstringNonRepeating("AABGAKG") // "AA" is repeated. "BGAKG".

  6. Aug 20, 2020 · Given a string, find the length of the longest substring without repeating characters. ( return int ) My Solution: public int lengthOfLongestSubstring(String s) {. //place holder for me to create a "sub-string". String sub = ""; //counter variable to count the characters in the substring. int count = 0;

  7. Apr 19, 2021 · I wrote this code in Python to solve the problem of Length of the longest substring without repeating characters. It works with small strings but not with larger strings. def lengthOfLongestSubstring(s): ns = [] ns[:0] = s. seq = ''. result = 0. for i in ns: if not(i in seq):

  8. Mar 1, 2018 · 2) variable naming. string and namestring may mean something to you here, but considering we're trying to find the longest substring (with the no double characters) in a string, I felt it was better to have the one we're checking against (tested) and the one we're storing to return later (longest).

  9. Apr 25, 2022 · 1. Question: Given a string s, return the longest palindromic substring in s. Example 1: Input: s = "babad" Output: "bab" Explanation: "aba" is also a valid answer. Example 2: Input: s = "cbbd" Output: "bb". My solution is. class Solution: def lengthOfLongestSubstring(self, s: str) -> int: substr = ''. length = longest_len = 0.

  10. Jul 3, 2021 · "check if that current character already exists there. If it does, I reset the array consideration, make current longest zero" - This is logically wrong. For example, if your string is abcade then the longest substring without repeating characters is bcade of length 5, but if you reset to 0 when you see the second a then you will not count all 5.

  1. People also search for