FastPrepCount Array Derangements
Problems/Count Array Derangements

Count Array Derangements

InMobi logoInMobi● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an InMobi phone screen. The interview report links the well-known task without giving its statement. Our version is about 99% the same as the linked task.

A derangement is a permutation in which no element remains in its original position.

You are given an integer n. Start with the array [1, 2, ..., n] in ascending order. Return the number of distinct derangements of this array.

Because the answer can be large, return it modulo 10^9 + 7.

Function

findDerangement(n: int) → int

Examples

Example 1

n = 3return = 2

The two derangements are [2, 3, 1] and [3, 1, 2].

Example 2

n = 2return = 1

The only derangement is [2, 1].

Constraints

  • 1 ≤ n ≤ 10^6

More InMobi Phone Screen questions

  • House Robber IPHONE SCREEN · Seen Aug 2026
  • Word Break IIPHONE SCREEN · Seen Aug 2026
  • Bus Station Seat AllotmentPHONE SCREEN · Seen Mar 2026
  • Find Missing and Duplicate IntegerPHONE SCREEN · Seen Mar 2026
  • Frequency Equals Card ValuePHONE SCREEN · Seen Mar 2026
  • Frog Position After T SecondsPHONE SCREEN · Seen Mar 2026
  • IPOPHONE SCREEN · Seen Mar 2026
  • Evaluate DivisionPHONE SCREEN · Seen Dec 2025
  • Compare Version NumbersPHONE SCREEN · Seen Feb 2022
  • Maximum Frequency StackPHONE SCREEN · Seen Feb 2022

Similar questions at other companies

  • Median of Uniform Draws in an IntervalSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
  • Biased Coin: Probability of Exactly h HeadsAkuna Capital · PHONE SCREENAkuna Capital interview questions
  • Probability of Consecutive HeadsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
  • Election District Budget Allocation AnalysisIMC Trading · PHONE SCREENIMC Trading interview questions
  • Count Clean Attendance LogsRippling · PHONE SCREENRippling interview questions
  • Heads in Fair Coin FlipsJane Street · PHONE SCREENJane Street interview questions
  • Count Staircases with Strictly Increasing StepseBay · ONSITE INTERVIEWeBay interview questions
  • Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions
  • Find Encrypted NumberAmazon · OA
  • Valid PasswordsMathWorks · OAMathWorks interview questions
All InMobi interview questionsSee InMobi hiring insights
Saved
class Solution {
    public int findDerangement(int n) {
      // write your code here
    }
}
Checking account…