All Posts

Leetcode 889: Construct Binary Tree from Preorder and Postorder Traversal

You are given two integer arrays representing the preorder and postorder traversals of a binary tree. Your task is to reconstruct the binary tree from these two traversals and return the root node of the tree.

Leetcode 893: Groups of Special-Equivalent Strings

You are given an array of strings where each string is of the same length. In one move, you can swap any two characters at even indexed positions or any two characters at odd indexed positions in a string. Two strings are considered special-equivalent if they can be made identical after performing any number of such moves. Your task is to determine how many distinct groups of special-equivalent strings exist in the given array.

Leetcode 904: Fruit Into Baskets

You are visiting a farm where fruit trees are planted in a single row from left to right. Each tree produces one type of fruit, represented by an integer array fruits, where fruits[i] is the type of fruit the ith tree produces. You have two baskets, and each basket can hold an unlimited amount of one type of fruit. Starting from any tree, you must pick exactly one fruit from each tree while moving to the right until the fruits cannot fit into your baskets. Determine the maximum number of fruits you can collect.

Leetcode 911: Online Election

You are given two integer arrays: persons and times. The i-th vote was cast for persons[i] at time times[i]. For each query at a given time t, you need to return the person who was leading the election at time t. If there is a tie between candidates, the most recent vote wins.

Leetcode 916: Word Subsets

Given two arrays of strings words1 and words2, find all the strings in words1 that are universal. A string from words1 is considered universal if it contains all the letters of every string in words2, including multiplicity. Each string in words2 is a subset of the string from words1.

Leetcode 930: Binary Subarrays With Sum

You are given a binary array nums and an integer goal. Your task is to return the number of non-empty contiguous subarrays that have a sum equal to the given goal. A subarray is defined as any contiguous part of the array.