You are given an array of integers where each element represents the cost of hiring a worker. You need to hire exactly k workers by running k sessions. In each session, choose the worker with the lowest cost from either the first ‘candidates’ workers or the last ‘candidates’ workers. If there is a tie, choose the worker with the smallest index.
You are given an m x n binary matrix grid. You need to create a difference matrix diff where each element diff[i][j] is calculated by summing the number of ones and subtracting the number of zeros in the respective row and column.
You are given a matrix grid with positive integers. In each operation, remove the greatest value from each row, and if multiple elements have the same greatest value, remove any one of them. After removing the greatest value from all rows, add the maximum of these values to the answer. The number of columns decreases by one after each operation. Perform these operations until the grid is empty, and return the sum of the maximum values from all operations.
Design a memory allocator class with functions to allocate and free blocks of memory. The allocator should efficiently handle consecutive memory requests and be able to free blocks based on their identifiers.
You are given a positive integer n. The task is to repeatedly replace n with the sum of its prime factors, and continue this process until n reaches a value that cannot be reduced further. The process stops when the sum of the prime factors is equal to the current value of n. Return the smallest value n will eventually become.
You are given a positive integer n, initially placed on a board. For each number x on the board, find all integers i such that 1 <= i <= n and x % i == 1. Add these numbers to the board. Your goal is to determine how many distinct integers will be present on the board after a billion days.