Tip 1: Practice daily on coding platforms.
Tip 2: Prepare core computer science subjects.
Tip 1: Don’t include false information on your resume.
Tip 2: Be confident about everything you’ve mentioned on your resume.



1. ‘.’ matches to any single character.
2. ‘*’ matches to zero or more of the preceding element.
1. You have to match the entire string with the pattern given.
2. Both the strings, 'S' and 'P' contain only lower-case alphabets.
3. Only the pattern will contain additional characters ‘*’ and ‘.’ along with alphabets.
Understanding the Problem:
The input string s and pattern p need to be matched according to specific rules:
. matches any single character.
* matches zero or more of the preceding element.
The goal is to determine if the pattern p matches the entire string s.
Initial Approach:
I started by considering a recursive solution, where I would compare characters one by one. The base case would be when both the string s and the pattern p are fully traversed.
Recursive Solution:
If the pattern’s current character is *, I considered two cases:
The * matches zero characters: Move to the next character in the pattern.
The * matches one or more characters: Move to the next character in the string while keeping the pattern unchanged.
If the current character in the pattern is ., I simply moved to the next characters in both s and p.
For other characters, I checked for an exact match and proceeded accordingly.
Optimization with Dynamic Programming:
The recursive approach led to overlapping subproblems, so I optimized the solution using dynamic programming.
I created a 2D DP table where dp[i][j] indicates whether the substring s[0...i] matches the pattern p[0...j].
I iteratively filled the table based on the conditions for . and *.
This approach ensured that I avoided redundant computations and handled all edge cases.
Final Solution:
The optimized DP solution provided an efficient and scalable approach to solving the problem.
I discussed edge cases, such as patterns ending in * and the importance of ensuring that the entire string is matched.


1. Both the strings are non-empty and are of the same length.
2. You can apply the above operations any number of times on ‘S’.
3. The operations can only be applied on the string ‘S’.
4. ‘S’ and 'R' consist of lowercase letters only.
Understanding the Problem:
You are given two strings, s1 and s2, of the same length.
The task is to determine if s2 can be obtained by scrambling s1 using the given recursive algorithm.
Recursive Approach:
I began by considering a recursive approach:
If s1 is equal to s2, return true.
If the sorted versions of s1 and s2 are not equal, return false (as they don't have the same characters).
Otherwise, I recursively checked every possible split of s1 into two substrings to see if swapping or not swapping them could produce s2.
Splitting and Recursion:
For each split of s1 into x and y, I considered two cases:
Without swapping: Check if s1[0...i] matches s2[0...i] and s1[i+1...n] matches s2[i+1...n].
With swapping: Check if s1[0...i] matches s2[n-i...n] and s1[i+1...n] matches s2[0...n-i].
If either case is true, then s2 is a scrambled string of s1.
Optimization with Memoization:
The recursive solution led to a lot of overlapping subproblems. To optimize this, I used memoization to store the results of already computed subproblems.
I used a 3D dictionary (or hash map) to store results of whether the substring s1[i...j] can be scrambled to form s2[i...j].
Final Implementation:
By combining recursion with memoization, I was able to reduce the time complexity and make the solution more efficient.
The solution correctly handles all possible ways of scrambling and returns true if any valid scramble can form s2.



Input: 'str' = "aaccb"
Output: 2
Explanation: We can make a valid partition like aa | cc | b.
Understanding the Problem:
Given a string s, the goal is to determine the minimum number of cuts required to partition s into substrings where each substring is a palindrome.
A palindrome is a string that reads the same forward and backward.
Initial Approach:
The most straightforward approach would be to check all possible partitions of the string and count the number of cuts needed to ensure all substrings are palindromes. However, this would involve generating all partitions and is computationally expensive.
Dynamic Programming (DP) Approach:
To optimize, I considered using dynamic programming:
Step 1: Palindrome Checking:
Create a 2D DP table isPalindrome[i][j] where isPalindrome[i][j] is true if the substring s[i...j] is a palindrome.
This can be filled by checking if s[i] == s[j] and isPalindrome[i+1][j-1] is true.
Step 2: Minimum Cuts Calculation:
Create a DP array minCuts[i] where minCuts[i] stores the minimum cuts required for the substring s[0...i].
Initialize minCuts[i] as i (the worst case where every character is its own palindrome).
For each i, if s[0...i] is a palindrome, then minCuts[i] = 0 (no cut needed).
Otherwise, update minCuts[i] by checking all possible cuts at j (from 0 to i-1)
Final Solution:
The final solution involves iterating over the string and filling both isPalindrome and minCuts tables.
The result is minCuts[n-1], where n is the length of the string s.



The same word in the dictionary can be used multiple times to make sentences.
Assume that the dictionary does not contain duplicate words.
Understanding the Problem:
You are given a string s and a dictionary wordDict.
The goal is to insert spaces in s to form all possible sentences where each word in the sentence exists in wordDict.
The same word from wordDict can be reused multiple times.
Initial Approach:
A naive approach would involve trying every possible way to partition the string and checking if each partition is a valid word from wordDict. This, however, would be computationally expensive due to the number of possible partitions.
Recursive Backtracking with Memoization:
To optimize the solution, I considered using recursive backtracking:
Start from the beginning of the string s and try to match every prefix of s with words in wordDict.
For every valid prefix found, recursively solve the problem for the remaining substring.
Combine the results of valid prefixes to form complete sentences.
Optimization with Memoization:
Since the same substrings might be processed multiple times in different recursive calls, I used memoization to store the results of already computed substrings.
The memoization table stores all possible sentences that can be formed starting from a given index.
Implementation Steps:
Step 1: Base Case:
If the start index reaches the end of the string s, return an empty list (indicating no more words to process).
Step 2: Recursive Case:
For every index i from the current start index to the end of the string:
Check if the substring s[start:i+1] is a valid word in wordDict.
If valid, recursively call the function for the remainder of the string (s[i+1:]).
Combine the current word with the results of the recursive call to form complete sentences.
Store the result in the memoization table to avoid reprocessing.
Step 3: Return Result:
Once the function processes the entire string, return the list of valid sentences.

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
What is recursion?