FastPrepMonotonic-Run Shuffle Score
Problems/Monotonic-Run Shuffle Score

Monotonic-Run Shuffle Score

Microsoft logoMicrosoft● EasyFULLTIMEONSITE INTERVIEW

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Microsoft Applied Scientist internship report asks for a shuffledness measure; the candidate proposed monotonic-sequence count divided by list length and discussed value distances as a follow-up. Distinct values, strict maximal runs, direction-change handling, interface, and bounds are conventional enrichment.

Given a nonempty array nums of distinct integers, divide it into maximal contiguous strictly monotonic runs. A run is either strictly increasing or strictly decreasing, and a new run begins whenever the sign of the adjacent difference changes.

Return the number of runs divided by nums.length as a simple shuffledness score.

Function

shuffleScore(nums: int[]) → double

Examples

Example 1

nums = [1,2,3,4]return = 0.25

The entire array is one increasing run, so the score is 1 / 4.

Example 2

nums = [1,3,2,4]return = 0.75

The direction changes twice, creating three runs, so the score is 3 / 4.

Constraints

  • 1 <= nums.length <= 100000
  • -10^9 <= nums[i] <= 10^9
  • All values are distinct
  • Results use absolute tolerance 1e-12

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Ring Buffer OperationsAmazon · ONSITE INTERVIEW
  • Count Distinct Underwriting PII ValuesAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
  • Bounded Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
  • Generate an Unbiased Bit from a Biased CoinGoogle · ONSITE INTERVIEWGoogle interview questions
  • Apply Overridden Integer TransformsOptimus Information · ONSITE INTERVIEWOptimus Information interview questions
  • Policy Violation Set ChecksPinterest · ONSITE INTERVIEWPinterest interview questions
  • Retry with an Attempt LimitOracle · ONSITE INTERVIEWOracle interview questions
  • Extract Error Log ContextFlexTrade · ONSITE INTERVIEWFlexTrade interview questions
  • Moving Cost by Volume and CategoryWayfair · ONSITE INTERVIEWWayfair interview questions
  • Alternate Positive and Negative ValuesTesla · ONSITE INTERVIEWTesla interview questions

Interview reports that mention this question

  • Microsoft AI/ML Intern Interviews: 114 Experiences (Part 1 of 2)

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public double shuffleScore(int[] nums) {
      // Write your code here.
    }

}
Checking account…