Grokking LinkedIn Coding Interview
Vote

0% completed

​
Hidden Document
Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content

.....

.....

.....

Like the course? Get enrolled and start learning!
Barsik Samogonov

Barsik Samogonov

· a month ago

Constraint mismatch: 1 <= s.length stated, but test case passes "" (length 0)

The problem states:

1 <= s.length <= 2 * 10^5

However, one of the test cases passes an empty string s = "". I confirmed this by logging at the very start of the function:

if (s === "") {

console.log(logging test case input "${s}" and length ${s.length});

}

Output: logging test case input "" and length 0

Should the constraints be updated to 0 <= s.length, or is this test case an error in the suite?

Show 1 reply
Sushant Gautam

Sushant Gautam

· 2 months ago

class Solution: def isPalindrome(self, s: str) -> bool: cleaned_l = [char.lower() for char in s if char.isalpha() or char.isdigit()] # two pointer l = 0 r = len(cleaned_l) - 1 while l < r: if cleaned_l[l] != cleaned_l[r]: return False l += 1 r -= 1 return True
Show 1 reply
Ana Calin

Ana Calin

· a year ago

Here's my solution for the palindrome problem that compiles and runs successfully on my editor:

package main import ( "fmt" "regexp" "strings" ) type Solution struct { } func (sol *Solution) isPalindrome(s string) bool { first, last := 0, len(s)-1 for first < last { if s[first] != s[last] { return false } first++ last-- } return true } func normalise(s string) string { toLowerStr := strings.ToLower(s) reg := regexp.MustCompile(`[^a-z]`) transformedStr := reg.ReplaceAllString(toLowerStr, "") return transformedStr } func main() { str := "A man, a plan, a canal, Panama!" normalisedStr := normalise(str) solution := Solution{} fmt.Println("Is my string a palindrome?", solution.isPalindrome(normalisedStr)) }

However

Show 1 reply
Amber Wolf

Amber Wolf

· a year ago

public bool IsPalindrome(string s) { // use Regex to easily remove special characters and spaces from our string var trimmedString = Regex.Replace(s, "[^a-zA-Z0-9]", "").ToLower(); // create an array from the string so we can iterate through it trimmedString.ToCharArray(); // we need to track both the Forward facing and Backward facing iterations of this array so I am initializing the index starting at the end of the array here. int j = trimmedString.Length - 1; // each time we loop through our array we will increase i and decrease j to compare both the forward and backward letter of the string. for (int i = 0; i < trimmedString.Length; i++, j--) { if (trimmedString[i] != trimmedString[j])
Show 1 reply
Akshay Hedau

Akshay Hedau

· 3 years ago

class Solution {   public boolean isPalindrome(String s) {     // TODO: Write your code here     s = s.toLowerCase();     int st = 0;     s = s.toLowerCase();     int ed = s.length() - 1;     char[] curS = s.toCharArray();     while (st < ed) {       char curSt = curS[st];       char curEd = curS[ed];       if (curSt > 'a' && curSt < 'z' && curEd > 'a' && curEd < 'z') {         if (curSt != curEd) return false;         st++;         ed--;       } else if (curSt > 'a' && curSt < 'z') {         ed--;       } else if (curEd > 'a' && curEd < 'z') {         st++;       } else {         st++;         ed--;       }     }     return true;   } }
Show 1 reply
T

Thai Minh

· 3 years ago

class Solution:   def isPalindrome(self, s: str) -> bool:     # TODO: Write your code here     str_array = []     for char in s:       if char.isalpha() or char.isdigit():         str_array.append(char.lower())     front, back = 0, len(str_array) - 1     while front < back:       if str_array[front] != str_array[back]:         return False       front += 1       back -= 1     return True
Show 1 reply

Reading Progress

0%


Vote for new content