Longest Common Subsequence LCS 1 - Get Length

Problem Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters. For example, "ace" is a subsequence of "abcde". A common subsequence of two strings is a subsequence that is common to both strings. ...

Longest Palindromic Substring Problem

Problem Given a string s, return the longest palindromic substring in s. Incase of conflict, return the substring which occurs first ( with the least starting index ). Substring of string S: S[i...j] where 0 <= i <= j < len(S) Example Example 1: Input: s = "babad" Output: "bab" Explanation: "aba" is also a valid answer. ...

Convert String to Integer atoi Problem

Problem Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer. The algorithm for myAtoi(string s) is as follows: Whitespace: Ignore any leading whitespace (" "). Signedness: Determine the sign by checking if the next character is '-' or '+', assuming positivity is neither present. Conversion: Read the integer by skipping leading zeros until a non-digit character is encountered or the end of the string is reached. If no digits were read, then the result is 0. Rounding: If the integer is out of the 32-bit signed integer range [-2^31, 2^31 - 1], then round the integer to remain in the range. Specifically, integers less than -2^31 should be rounded to -2^31, and integers greater than 2^31 - 1 should be rounded to 2^31 - 1. Return the integer as the final result. ...

Group Anagrams Problem

Problem Given an array of strings strs, group the anagrams together. You can return the answer in any order. Definition Anagram Definition Examples For example, suppose that we have the following strings: Example 1: Input: strs = ["eat","tea","tan","ate","nat","bat"] Output: [ ["bat"],["nat","tan"],["ate","eat","tea"] ] ...

Reverse String Problem

Problem Write a function that takes a string as input and returns the string reversed. Examples Example 1: Given s = "hello", return "olleh". Given s = “kodeknight” , return “thginkedok“. Solution Method 0 - Iterative, Not in Place In Java, string is immutable. So, cannot do in place!. public String reverseString(String s) { int n = s.length; char[] reversed = s.toCharArray(); return reverse(reversed); } ...

Valid Anagram Problem

Problem Given two strings s and t, return true if t is an anagram of s, and false otherwise. OR WAP to find out if 2 strings are anagrams or not. Anagram Definition Examples Example 1: Input: s = "anagram", t = "nagaram" Output: true Example 2: Input: s = "rat", t = "car" Output: false ...

Manachar’s Algorithm - Longest palindromic substring in linear time

Problem Given a string, find the longest palindromic substring in linear time i.e. substring that is also a palindrome. Subsequently, Find all palindromic substrings of a given string We have already seen simple O(n^2) solution here - Longest Palindromic Substring Problem, but now lets look at Manacher’s Algorithm, which help us find the solution in linear time. Manacher’s Algorithm #TODO complete this

Isomorphic Strings Problem

Problem Given two strings s and t, determine if they are isomorphic. Definition Two strings s and t are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself. Example Example 1: ...

Length of Last Word

Length of Last Word Problem Given a string s consisting of some words separated by some number of spaces, return the length of the last word in the string. A word is a maximal substring consisting of non-space characters only. Examples Example 1: Input: s = "Hello World" Output: 5 Explanation: The last word is "World" with length 5. ...

First Unique Character in a String

Find First Unique Character in a String Problem Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1. Examples Example 1: Input: s = "leetcode" Output: 0 Example 2: Input: s = "loveleetcode" Output: 2 ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy