Java Python Strings
Category: Strings
This guide covers five popular interview questions in both Java and Python.
Valid Anagram
Overview
Valid Anagram is one of the most frequently asked coding interview questions.
Algorithm
Frequency count.
Complexity: O(n)
Tip: Compare counts.
Python
class Solution:
def solve(self,*args):
# TODO: implement Valid Anagram
pass
Java
class Solution {
// TODO: implement Valid Anagram
}
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Longest Substring
Overview
Longest Substring is one of the most frequently asked coding interview questions.
Algorithm
Sliding window.
Complexity: O(n)
Tip: Move left pointer on duplicates.
Python
class Solution:
def solve(self,*args):
# TODO: implement Longest Substring
pass
Java
class Solution {
// TODO: implement Longest Substring
}
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Valid Palindrome
Overview
Valid Palindrome is one of the most frequently asked coding interview questions.
Algorithm
Two pointers.
Complexity: O(n)
Tip: Ignore punctuation.
Python
class Solution:
def solve(self,*args):
# TODO: implement Valid Palindrome
pass
Java
class Solution {
// TODO: implement Valid Palindrome
}
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Group Anagrams
Overview
Group Anagrams is one of the most frequently asked coding interview questions.
Algorithm
Sort key.
Complexity: O(nklogk)
Tip: Hash by sorted word.
Python
class Solution:
def solve(self,*args):
# TODO: implement Group Anagrams
pass
Java
class Solution {
// TODO: implement Group Anagrams
}
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Longest Palindrome
Overview
Longest Palindrome is one of the most frequently asked coding interview questions.
Algorithm
Expand centres.
Complexity: O(n²)
Tip: Expand around each index.
Python
class Solution:
def solve(self,*args):
# TODO: implement Longest Palindrome
pass
Java
class Solution {
// TODO: implement Longest Palindrome
}
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.
Interview advice: explain your approach before coding, discuss edge cases, analyse time and
space complexity, and test your solution using small examples. Practising this problem
repeatedly improves pattern recognition.