We are given a run-length encoded array where every even-indexed element specifies how many times the following odd-indexed element (a number) is repeated in the original sequence. Your task is to implement an iterator that can return the next ’n’ elements from the decoded sequence when requested.
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.
Given an array of integers arr, find the sum of the minimum values of all contiguous subarrays of arr. Since the result can be very large, return it modulo 10^9 + 7.
You are given an n x n integer matrix board where the cells are numbered from 1 to n² in a zigzag pattern starting from the bottom-left corner. Each cell may contain either -1 (indicating no special feature) or a number indicating a snake or ladder destination. You start at square 1 and can roll a 6-sided die to move between 1 and 6 steps. If you land on a square with a snake or ladder, you must move to its destination. Determine the minimum number of dice rolls needed to reach the final square n². Return -1 if it is not possible.
You are given an integer array nums and an integer k. For each element in nums, you can either add or subtract k. The score of the array is calculated as the difference between the maximum and minimum elements of the modified array. Your task is to find and return the minimum possible score after modifying the values in the array.
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.