All Posts

Leetcode 121: Best Time to Buy and Sell Stock

You are given an array of prices where prices[i] represents the price of a stock on the i-th day. You want to maximize your profit by buying the stock on one day and selling it on a future day. Return the maximum profit you can achieve from this transaction. If no profit can be made, return 0.

Leetcode 128: Longest Consecutive Sequence

Given an unsorted array of integers, return the length of the longest consecutive elements sequence.

Leetcode 130: Surrounded Regions

You are given an m x n matrix board containing letters ‘X’ and ‘O’. Capture all regions that are surrounded by ‘X’. A region is captured if it is surrounded by ‘X’ cells and cannot reach the edges of the board.

Leetcode 134: Gas Station

You are given ’n’ gas stations along a circular route, where each station has a certain amount of gas and a cost associated with traveling to the next station. The goal is to find the starting station from where you can complete a full circle. If no such starting station exists, return -1.

Leetcode 136: Single Number

Given a non-empty array of integers where every element appears twice except for one element that appears once, find the single element that appears only once. The solution must have linear time complexity and use only constant space.

Leetcode 137: Single Number II

You are given an integer array where every element appears exactly three times, except for one element which appears only once. Find the element that appears only once and return it. The solution must run in linear time complexity and use constant extra space.