Bigdata – Knowledge Base

Practice Problem – String

  1. String Compression
    • Write a function that takes a string and compresses it using the counts of repeated characters. For example, the string “aabcccccaaa” should become “a2b1c5a3”. If the compressed string is not smaller than the original string, return the original string.
  2. Longest Substring Without Repeating Characters
    • Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating characters for “abcabcbb” is “abc”, which the length is 3.
  3. String Permutations
    • Write a function to check if two given strings are permutations of each other. For example, “abc” and “bca” are permutations of each other, but “abc” and “abcd” are not.
  4. Palindrome Substring
    • Given a string, find the longest palindromic substring. For example, for the input “babad”, the longest palindromic substring is “bab” or “aba”.
  5. Regular Expression Matching
    • Implement a function to perform basic regular expression matching with support for ‘.’ and ‘‘. The function should take an input string and a pattern and return whether the pattern matches the entire input string. For example, “a” matches “aaa” and “.*” matches any string.
  6. Anagram Grouping
    • Given a list of strings, group the anagrams together. For example, given ["eat", "tea", "tan", "ate", "nat", "bat"], return [["eat", "tea", "ate"], ["tan", "nat"], ["bat"]].
  7. ZigZag Conversion
    • Write a function that converts a string to a zigzag pattern on a given number of rows. For example, the string “PAYPALISHIRING” on 3 rows should be printed
    • P A H N
    • A P L S I I G
    • Y I R
  8. Word Search in Matrix
    • Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where “adjacent” cells are horizontally or vertically neighboring. The same letter cell may not be used more than once.
  9. Minimum Window Substring
    • Given a string S and a string T, find the minimum window in S which will contain all the characters in T. For example, S = "ADOBECODEBANC" and T = "ABC", the minimum window is “BANC”.
  10. String to Integer (atoi)
    • Implement the atoi function, 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.

What are your feelings
Updated on July 18, 2024