PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Uber

Determine balanced k values in a permutation

Last updated: May 14, 2026

Quick Overview

This question evaluates algorithmic reasoning about permutations and contiguous subarray properties, testing skills in array manipulation, positional reasoning, combinatorial insight, and complexity-aware algorithm design within the Coding & Algorithms domain.

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Determine balanced k values in a permutation

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

You are given a permutation `p` of the integers `1..n`. For a number `k` (where `1 <= k <= n`), call `k` **balanced** if there exists a contiguous subarray `p[l..r]` such that: - `r - l + 1 = k`, and - the multiset of values in `p[l..r]` is exactly `{1, 2, ..., k}` (i.e., the subarray is a permutation of `1..k`). Your task: for every `k = 1..n`, determine whether `k` is balanced and return a binary string `s` of length `n` where: - `s[k-1] = '1'` if `k` is balanced - `s[k-1] = '0'` otherwise ### Input - An integer `n` - A permutation `p` of length `n` *(If your platform uses multiple test cases, solve independently per test case.)* ### Output - A binary string of length `n`. ### Example If `n = 5` and `p = [4, 1, 3, 2, 5]`, you should output a string of length 5 indicating which `k` are balanced. ### Constraints Assume `n` can be large (e.g., up to `2e5`), so an `O(n log n)` or `O(n)` approach is expected.

Quick Answer: This question evaluates algorithmic reasoning about permutations and contiguous subarray properties, testing skills in array manipulation, positional reasoning, combinatorial insight, and complexity-aware algorithm design within the Coding & Algorithms domain.

Related Interview Questions

  • Implement stream queries and bounded-difference subarrays - Uber (medium)
  • Implement Minesweeper and Word Search - Uber (medium)
  • Implement Store Autocomplete - Uber (medium)
  • Simulate a Rank-Based Tournament - Uber (medium)
  • Implement Cache Eviction And Seat Assignment - Uber (medium)
Uber logo
Uber
Feb 11, 2026, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
23
0

You are given a permutation p of the integers 1..n.

For a number k (where 1 <= k <= n), call k balanced if there exists a contiguous subarray p[l..r] such that:

  • r - l + 1 = k , and
  • the multiset of values in p[l..r] is exactly {1, 2, ..., k} (i.e., the subarray is a permutation of 1..k ).

Your task: for every k = 1..n, determine whether k is balanced and return a binary string s of length n where:

  • s[k-1] = '1' if k is balanced
  • s[k-1] = '0' otherwise

Input

  • An integer n
  • A permutation p of length n

(If your platform uses multiple test cases, solve independently per test case.)

Output

  • A binary string of length n .

Example

If n = 5 and p = [4, 1, 3, 2, 5], you should output a string of length 5 indicating which k are balanced.

Constraints

Assume n can be large (e.g., up to 2e5), so an O(n log n) or O(n) approach is expected.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Uber•More Software Engineer•Uber Software Engineer•Uber Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.