Skip to main content

Posts

Leetcode 38: Count and Say

  1. Problem Statement (Simple Explanation): We define a sequence of strings countAndSay(n): Base: countAndSay(1) = "1" Recursive: countAndSay(n) = RLE(countAndSay(n-1)) where RLE =  run-length encoding  of the previous term. Run-Length Encoding (RLE)  here means: Read the string  left to right . Group consecutive identical characters. For each group k of character c, append: the count k followed by the character c. Example of RLE: "3322251": "33" → "23" (two 3s) "222" → "32" (three 2s) "5" → "15" (one 5) "1" → "11" (one 1) Combined: "23321511". You must return countAndSay(n) as a string. 2. Examples: Example 1: Input: n = 4 Sequence: n = 1: "1" n = 2: RLE("1") → one 1 → "11" n = 3: RLE("11") → two 1s → "21" n = 4: RLE("21") → one 2, then one 1 → "12" + "11" = "1211" Output: "1211...
Recent posts

Leetcode 37: Sudoku Solver

  1. Problem Statement (Simple Explanation): You are given a  9×9  Sudoku board, partially filled, with: Digits '1'–'9' for filled cells. '.' for empty cells. You must: Fill the empty cells  so that the final board is a  valid Sudoku solution : Each digit 1–9 appears exactly once in each  row . Each digit 1–9 appears exactly once in each  column . Each digit 1–9 appears exactly once in each  3×3 sub-box . The input is guaranteed to have  exactly one solution . You must modify the board  in-place . 2. Example: Input board: [   ["5","3",".",".","7",".",".",".","."],   ["6",".",".","1","9","5",".",".","."],   [".","9","8",".",".",".",".","6","."],   ["8",".",".","....