All Posts

Leetcode 840: Magic Squares In Grid

Given a grid of integers, the task is to find how many 3x3 magic square subgrids are present in the given grid. A 3x3 magic square is a grid that contains distinct numbers from 1 to 9, such that each row, each column, and both diagonals have the same sum. The input grid can contain numbers ranging from 0 to 15, but only numbers between 1 and 9 are valid for forming a magic square.

Leetcode 841: Keys and Rooms

You are in a building with multiple rooms, each containing a set of keys to unlock other rooms. Initially, only the first room (room 0) is unlocked. You are tasked with determining whether you can visit all the rooms, starting from room 0. To enter a locked room, you must have its corresponding key, which can only be obtained by visiting other rooms.

Leetcode 842: Split Array into Fibonacci Sequence

You are given a string of digits, and you need to split it into a sequence of integers that follow the Fibonacci-like property. In other words, the sum of the first two numbers should equal the third, the sum of the second and third should equal the fourth, and so on. Your goal is to find any valid Fibonacci-like sequence from the digits, or return an empty list if it’s not possible.

Leetcode 845: Longest Mountain in Array

Given an integer array arr, you need to find the length of the longest subarray that forms a mountain. A mountain subarray has the following properties: it must have at least three elements, the elements strictly increase to a peak, and then strictly decrease after the peak. If no such subarray exists, return 0.

Leetcode 846: Hand of Straights

Alice has a set of cards, each with a value written on it. She wants to rearrange these cards into groups, where each group consists of groupSize consecutive cards. Given an integer array hand where hand[i] represents the value on the ith card, and an integer groupSize, return true if she can rearrange the cards into groups of consecutive numbers, or false otherwise.

Leetcode 848: Shifting Letters

You are given a string s of lowercase English letters and an array shifts, where shifts[i] represents the number of times to shift the first i + 1 characters of s. The shift operation for a letter means moving to the next letter in the alphabet, and if the letter is ‘z’, it wraps around to ‘a’. After applying all the shifts, return the final string.