Skip to content

Instantly share code, notes, and snippets.

View varnie's full-sized avatar

Sergei A. varnie

View GitHub Profile
"""
String compression
You are given an array of characters chars, consisting of letters or numbers. Implement a data compression algorithm that modifies the original array as follows:
If a group of consecutive characters is repeated once, it remains unchanged.
If a group is repeated more than once, the character is replaced by the character itself, followed by the length of the group.
Return the new length of the array after compression.
Notes:
"""
Longest substring without repetitions
Given a string s, find the length of the longest substring without repeating characters.
A substring is a continuous non-empty sequence of characters within a string.
Example 1:
Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc" whose length is 3.
"""
Sum of two
Given an array of integers nums and an integer target. Return the indices of the two numbers whose sum is target.
You can assume that for each input array there is exactly one solution, and the same element cannot be used twice.
You can return the answer in any order.
Example 1:
"""
Valid Parentheses
Given a string s consisting only of the characters '(', ')', '{', '}', '[', and ']', determine whether the input string is valid.
A string is valid if:
Open parentheses must be closed by parentheses of the same type.
Open parentheses must be closed in the correct order.
Each closing parenthesis has a corresponding opening parenthesis of the same type.
```
Intersection of two arrays II
Given two integer arrays nums1 and nums2, return the array of their intersection.
Each element in the result must appear as many times as it appears in both arrays.
You can return the result in any order.
Example 1:
"""
Consecutive characters
The cardinality of a string is the maximum length of a non-empty substring that contains exactly one unique character.
You need to return the cardinality of the string s.
Example 1:
Input: s = "meet"
import re
"""
Longest word
You are given a string s. Return the longest word from it.
A word is a continuous sequence of letters; all other characters serve as separators and are not included in the word length.
If the string contains several words of maximum length, return the first of them in the order of their appearance.
import itertools
"""
The Longest Palindrome
You are given a string s consisting of lowercase or uppercase letters.
You need to determine the maximum length of a palindrome that can be made from the letters of this string.
The letters are case-sensitive, for example, the string "Aa" is not considered a palindrome.
"""
Missing number
You are given an array nums containing n different numbers in the range [0, n].
You need to return the only number from the range that is missing from the array.
Example 1:
Input: nums = [3,0,1]
"""
Given a positive integer n, return the number of integers in the range [0, n] whose binary representations do not contain two consecutive ones.
Example 1:
Input: n = 5
Output: 5
Explanation: