string:

String Compression

Given an array of characters, compress it in-place. The length after compression must always be smaller than or equal to the original array. Every element of the array should be a character (not int) of length 1. After you are done modifying the input array in-place, return the new length of the array. Follow up Could you solve it using only O(1) extra space? Example 1 Input: ["a","a","b","b","c","c","c"] Output: Return 6, and the first 6 characters of the input array should be: ["a","2","b","2","c","3"] Explanation: "aa" is replaced by "a2".

by lek tin in "algorithm" access_time 2-min read

Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. *### Example 1 Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. *### Example 2 Input: "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. *### Example 3 Input: "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.

by lek tin in "algorithm" access_time 1-min read

Add Strings

Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. Note The length of both num1 and num2 is < 5100. Both num1 and num2 contains only digits 0-9. Both num1 and num2 does not contain any leading zero. You must not use any built-in BigInteger library or convert the inputs to integer directly. Solution class Solution: def addStrings(self, num1: str, num2: str) -> str: if len(num1) < len(num2): return self.

by lek tin in "algorithm" access_time 1-min read

Reverse Words in a String

Given an input string, reverse the string word by word. Example 1 Input: "the sky is blue" Output: "blue is sky the" Example 2 Input: " hello world! " Output: "world! hello" Explanation: Your reversed string should not contain leading or trailing spaces. Example 3 Input: "a good example" Output: "example good a" Explanation: You need to reduce multiple spaces between two words to a single space in the reversed string.

by lek tin in "algorithm" access_time 2-min read

Most Common Word

Given a paragraph and a list of banned words, return the most frequent word that is not in the list of banned words. It is guaranteed there is at least one word that isn’t banned, and that the answer is unique. Words in the list of banned words are given in lowercase, and free of punctuation. Words in the paragraph are not case sensitive. The answer is in lowercase. Example: Input: paragraph = "Bob hit a ball, the hit BALL flew far after it was hit.

by lek tin in "algorithm" access_time 2-min read

String to Integer Atoi

Implement atoi which converts a string to an integer. The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value. The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.

by lek tin in "algorithm" access_time 2-min read

One Edit Distance

Given two strings s and t, determine if they are both one edit distance apart. Note There are 3 possiblities to satisify one edit distance apart: Insert a character into s to get t Delete a character from s to get t Replace a character of s to get t Example 1 Input: s = "ab", t = "acb" Output: true Explanation: We can insert 'c' into s to get t.

by lek tin in "algorithm" access_time 2-min read

Valid Number

Validate if a given string can be interpreted as a decimal number. Some examples: "0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => true " -90e3 " => true " 1e" => false "e3" => false " 6e-1" => true " 99e2.5 " => false "53.5e93" => true " --6 " => false "-+3" => false "95a54e53" => false Note It is intended for the problem statement to be ambiguous.

by lek tin in "algorithm" access_time 3-min read