All Posts

Leetcode 419: Battleships in a Board

You are given a grid representing a battleship field, where ‘X’ marks the location of a part of a battleship and ‘.’ represents an empty sea cell. A battleship is either placed horizontally or vertically on the grid, with no adjacent battleships (there must be at least one empty cell between any two battleships). Your task is to count the number of distinct battleships on the grid.

Leetcode 421: Maximum XOR of Two Numbers in an Array

Given an array of integers, your task is to find the maximum result of the XOR operation between any two elements from the array. The goal is to maximize the XOR value of any pair of numbers in the array, where the XOR of two numbers is computed using the bitwise XOR operation.

Leetcode 423: Reconstruct Original Digits from English

You are given a string representing an out-of-order English representation of digits from 0 to 9. Your task is to rearrange the characters of the string in such a way that you can extract the digits in ascending order. The string will only contain valid letters corresponding to the English representations of digits.

Leetcode 424: Longest Repeating Character Replacement

You are given a string s consisting of uppercase English letters and an integer k. You can change any character in the string to any other uppercase English character, but you are allowed to perform this operation at most k times. The goal is to find the length of the longest substring that contains the same letter after performing at most k character changes.

Leetcode 427: Construct Quad Tree

You are given an n x n binary grid of 0’s and 1’s. Your task is to represent this grid with a Quad-Tree. A Quad-Tree is a tree structure where each node has four children. Each internal node has two properties: val (True for a grid of 1’s or False for a grid of 0’s) and isLeaf (True if the node is a leaf, False if it has children). If the entire grid has the same value, the node is a leaf. If not, the grid is divided into four sub-grids, and the process is repeated recursively for each sub-grid. Your goal is to return the root of the Quad-Tree that represents the grid.

Leetcode 429: N-ary Tree Level Order Traversal

You are given an n-ary tree where each node contains a value and a list of its children. Your task is to return the level order traversal of the tree’s nodes. Nodes are grouped by their level, with the root node at level 0. Each node’s children are separated by a null value in the level order serialization.