Longest Palindrome Problem

Problem Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters. Letters are case sensitive, for example, "Aa" is not considered a palindrome here. Examples Example 1: Input: s = "abccccdd" Output: 7 Explanation: One longest palindrome that can be built is "dccaccd", whose length is 7. ...

Minimum Insertion Steps to Make a String Palindrome Problem

Problem Given a string s. In one step you can insert any character at any index of the string. Return the minimum number of steps to make s palindrome. A Palindrome String is one that reads the same backward as well as forward. Examples Example 1: Input: s = "zzazz" Output: 0 Explanation: The string "zzazz" is already palindrome we don't need any insertions. ...

Reverse Words in a String 2

Reverse Words in a String 2 Problem Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters. The input string does not contain leading or trailing spaces and the words are always separated by a single space. Follow up Could you do it in-place without allocating extra space? Examples Example 1: Input: s = "the sky is blue" Output: "blue is sky the" ...

Reverse Words in a String 3

Reverse Words in a String 3 Problem Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Examples Example 1: Input: s = "Let's take LeetCode contest" Output: "s'teL ekat edoCteeL tsetnoc" Example 2: Input: s = "God Ding" Output: "doG gniD" ...

Sort Characters By Frequency Problem

Problem Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string. Return the sorted string. If there are multiple answers, return any of them. Examples Example 1: Input: s = "tree" Output: "eert" Explanation: 'e' appears twice while 'r' and 't' both appear once. So 'e' must appear before both 'r' and 't'. Therefore "eetr" is also a valid answer. ...

What is Java String’s Immutability

Java strings are immutable ⇨ Once created, the content of the string cannot be changed. Any methods that seem to modify a String object, like concat, actually create a new String object with the desired changes. The original String object remains unchanged. Here are a set of diagrams to illustrate Java String’s immutability. Initializing string We can declare a string s: String s = "hello"; ...

Remove All Adjacent Duplicates In String 1

Problem You are given a string s consisting of lowercase English letters. A duplicate removal consists of choosing two adjacent and equal letters and removing them. We repeatedly make duplicate removals on s until we no longer can. Return the final string after all such duplicate removals have been made. It can be proven that the answer is unique. Examples Example 1: Input: s = "abbaca" Output: "ca" Explanation: For example, in "abbaca" we could remove "bb" since the letters are adjacent and equal, and this is the only possible move. The result of this move is that the string is "aaca", of which only "aa" is possible, so the final string is "ca". ...

Reverse String 2 Problem

Problem Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string. If there are fewer than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and leave the other as original. Examples Example 1: ...

Minimum Time Difference Problem

Problem Given a list of 24-hour clock time points in “HH:MM” format, return the minimum minutes difference between any two time-points in the list. Examples Example 1: Input: timePoints = ["23:59","00:00"] Output: 1 Example 2: Input: timePoints = ["00:00","23:59","00:00"] Output: 0 ...

Make The String Great Problem

Make The String Great Problem Problem Given a string s of lower and upper case English letters. A good string is a string which doesn’t have two adjacent characters s[i] and s[i + 1] where: 0 <= i <= s.length - 2 s[i] is a lower-case letter and s[i + 1] is the same letter but in upper-case or vice-versa. To make the string good, you can choose two adjacent characters that make the string bad and remove them. You can keep doing this until the string becomes good. ...

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