Solved! Leetcode 347. Top K Frequent Elements

source: https://leetcode.com/problems/top-k-frequent-elements/description/ Top K Frequent Elements Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input: nums = [1], k = 1 Output: [1] Constraints: 1 <= nums.length ...

Solved! Leetcode 1035. Uncrossed Lines

source: https://leetcode.com/problems/uncrossed-lines/description/ Uncrossed Lines You are given two integer arrays nums1 and nums2. We write the integers of nums1 and nums2 (in the order they are given) on two separate horizontal lines. We may draw connecting lines: a straight line connecting two numbers nums1[i] and nums2[j] such that: nums1[i] == nums2[j], and the line we ...

Solved! Leetcode 2466. Count Ways To Build Good Strings

source: https://leetcode.com/problems/count-ways-to-build-good-strings/description/ Count Ways To Build Good Strings Given the integers zero, one, low, and high, we can construct a string by starting with an empty string, and then at each step perform either of the following: Append the character ‘0’ zero times. Append the character ‘1’ one times. This can be performed any number ...

Solved! Leetcode 2130. Maximum Twin Sum of a Linked List

source: https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list/description/ Maximum Twin Sum of a Linked List In a linked list of size n, where n is even, the ith node (0-indexed) of the linked list is known as the twin of the (n-1-i)th node, if 0 <= i <= (n / 2) – 1. For example, if n = 4, then node ...

Solved Leetcode 1721: Swapping Nodes in a Linked List

source: https://leetcode.com/problems/swapping-nodes-in-a-linked-list/description/ Swapping Nodes in a Linked List You are given the head of a linked list, and an integer k. Return the head of the linked list after swapping the values of the kth node from the beginning and the kth node from the end (the list is 1-indexed). Example 1: Input: head = ...

Solved Leetcode 2140. Solving Questions With Brainpower

source: https://leetcode.com/problems/solving-questions-with-brainpower/description/ Solving Questions With Brainpower You are given a 0-indexed 2D integer array questions where questions[i] = [pointsi, brainpoweri]. The array describes the questions of an exam, where you have to process the questions in order (i.e., starting from question 0) and make a decision whether to solve or skip each question. Solving question ...

Solved! Leetcode 1498. Number of Subsequences That Satisfy the Given Sum Condition

source: https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition/description/ Number of Subsequences That Satisfy the Given Sum Condition You are given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal to target. Since the answer may be too ...

Solved! Leetcode 1046. Last Stone Weight

source: https://leetcode.com/problems/last-stone-weight/description/ Last Stone Weight You are given an array of integers stones where stones[i] is the weight of the ith stone. We are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them together. Suppose the heaviest two stones have weights x and y with x ...

Solved! Leetcode 1312. Minimum Insertion Steps to Make a String Palindrome

source: https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/description/ Minimum Insertion Steps to Make a String Palindrome Given a string s. In one step you can insert any character at any index of the string. Return the minimum number of steps to make s palindrome. A Palindrome String is one that reads the same backward as well as forward. Example 1: Input: ...

Solved! Leetcode 879. Profitable Schemes

source: https://leetcode.com/problems/profitable-schemes/description/ Profitable Schemes There is a group of n members, and a list of various crimes they could commit. The ith crime generates a profit[i] and requires group[i] members to participate in it. If a member participates in one crime, that member can’t participate in another crime. Let’s call a profitable scheme any subset ...