title-img


Maximum Number After One Swap - Facebook Top Interview Questions

Given an integer n, you can swap any two digits at most once. Return the maximum value of the resulting number. Constraints 0 ≤ n < 2 ** 31 Example 1 Input n = 1929 Output 9921 Explanation We swap the first and the last digits

View Solution →

Next Smaller Permutation - Facebook Top Interview Questions

You are given a list of integers nums. Given that you must first swap any two numbers in nums, return the lexicographically largest list which is smaller than nums. If there is no solution, then return the same list. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [2, 0, 1] Output [1, 0, 2] Explanation The largest permutation we can make that's less than nums is [1, 0, 2]. We swap 2 and 1. Note that [1, 2, 0] is not possible since get

View Solution →

Permute to Make List Larger - Facebook Top Interview Questions

You are given two lists of integers a and b, both of the same length. Given that you can first permute a in any order, return the maximum number of indices where a[i] > b[i]. Constraints n ≤ 100,000 where n is the length of a and b Example 1 Input a = [3, 5, 8, 1] b = [4, 7, 2, 1] Output 3 Explanation If we permute a to [5, 8, 3, 1].

View Solution →

Recursive Voting - Facebook Top Interview Questions

You are given a list of integers votes representing election votes for candidates a and b. Each element in votes represents a vote to one of the two candidates: If votes[i] < 0, then it's a vote for a. If votes[i] ≥ n, then it's a vote for b. Otherwise, the vote at index i made the same vote as votes[votes[i]]. Return the number of votes that candidate a received. You can assume all votes are eventually made to either a or b. Constraints 0 ≤ n ≤ 100,000 where n is the len

View Solution →

Set Split - Facebook Top Interview Questions

Given a list of positive integers nums, return whether you can divide the list into two groups a and b such that: The sum of a and the sum of b are equal. Every number in a is strictly less than every number in b. Constraints 1 ≤ n ≤ 100,000 where n is the length of nums. Example 1 Input nums = [4, 9, 5] Output True Explanation We can have a = [4, 5] and b = [9] and both of their sums are 9. Example 2 Input nums = [9, 9] Output False Explanati

View Solution →