title-img


Longest Consecutively Increasing Substring - Facebook Top Interview Questions

You are given a string s containing lowercase alphabet characters as well as "?". For each "?" you must either delete it or replace it with any lowercase alphabet character. Return the length of the longest consecutively increasing substring that starts with "a". Constraints 1 ≤ n ≤ 100,000 where n is the length of s Example 1 Input s = "bca???de" Output 5 Explanation We can turn s into "bcabcde" and "abcde" is the longest consecutively increasing substring th

View Solution →

Matrix Rectangular Sums - Facebook Top Interview Questions

Given a two-dimensional list of integers matrix and an integer k, return a new matrix M of the same dimensions where M[i][j] is the sum of all numbers sum(matrix[r][c]) for all (i - k ≤ r ≤ i + k, j - k ≤ c ≤ j + k) Constraints n, m ≤ 250 where n and m is the number of rows and columns in matrix Example 1 Input matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] k = 1 Output [ [12, 21, 16], [27, 45, 33], [24, 39, 28] ]

View Solution →

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 →