All Posts
Leetcode 1545: Find Kth Bit in Nth Binary String
Given two positive integers n and k, the binary string Sn is formed recursively. The task is to return the kth bit in the string Sn.
Leetcode 1562: Find Latest Group of Size M
You are given a permutation of integers from 1 to n, where each integer represents a position in a binary string of size n that is initially filled with zeros. At each step, you will flip the bit at the position specified by the current element of the array. You are also given an integer m, and your task is to determine the latest step at which there exists a contiguous substring of exactly m ones in the binary string.
Leetcode 1583: Count Unhappy Friends
You are given a list of preferences for n friends, where n is always even. Each person has a list of friends they prefer, and these friends are represented by integers from 0 to n-1. The friends are divided into pairs, where each pair is denoted by a list [xi, yi], meaning xi is paired with yi and yi with xi. However, some of the pairings may cause unhappiness. A person is unhappy if they prefer someone who is paired with someone else, and that person also prefers them over their current partner. Your task is to return the number of unhappy friends.
Leetcode 1599: Maximum Profit of Operating a Centennial Wheel
You operate a giant Ferris wheel with four gondolas, each holding up to four passengers. The Ferris wheel rotates counterclockwise and incurs a running cost for every rotation. You are given a list of customer arrivals, where each entry indicates the number of customers arriving just before the ith rotation. Customers board the gondola closest to the ground, and only a maximum of four customers can board at any time, while any excess wait for the next rotation. Each customer pays a boarding cost. Your task is to determine the minimum number of rotations needed to achieve the maximum profit. If there is no scenario where the profit is positive, return -1.
Leetcode 1603: Design Parking System
ParkingSystem
class that supports the operations of initializing the parking system and parking a car based on its type.
You are tasked with designing a parking system for a parking lot that has three types of parking spaces: large, medium, and small. Each type of parking space has a fixed number of available slots. Your goal is to implement the Leetcode 1646: Get Maximum in Generated Array
Given an integer n, an array nums of length n+1 is generated with the following rules:
- nums[0] = 0
- nums[1] = 1
- nums[2 * i] = nums[i] when 2 <= 2 * i <= n
- nums[2 * i + 1] = nums[i] + nums[i + 1] when 2 <= 2 * i + 1 <= n
Return the maximum value in the array nums.