In this game, you must guess a number between 1 and n. Each wrong guess costs you the amount of the guessed number. Your goal is to minimize the total cost while guaranteeing a win. If you run out of money, you lose the game.
Design a data structure that supports three operations: insert, remove, and getRandom. The insert operation adds an element to the set if it is not already present. The remove operation removes an element from the set if it exists. The getRandom operation returns a random element from the set, with each element having an equal probability of being selected.
Given a singly linked list, implement a class that supports the initialization of the list and the ability to return a random node’s value with equal probability.
You are given an integer array nums. Design an algorithm to randomly shuffle the array. All permutations of the array should be equally likely as a result of the shuffling.
Given an integer n, simulate a process on a list of integers from 1 to n where every other number is removed, alternating the direction from left to right and right to left until only one number remains. Return the last remaining number.
You are given an integer array nums of length n. For each rotation k, we define a function F(k) which is calculated as: F(k) = 0 * arrk[0] + 1 * arrk[1] + … + (n-1) * arrk[n-1]. The goal is to return the maximum value of F(k) for all possible k in the range from 0 to n-1.