PracHub
QuestionsPremiumLearningGuidesInterview PrepCoaches
|Home/Coding & Algorithms/Airbnb

Construct smallest number from I/D pattern

Last updated: Apr 19, 2026

Quick Overview

This question evaluates a candidate's ability to reason about permutation constraints, sequence ordering, and combinatorial construction under digit-uniqueness and numeric-minimization requirements.

  • medium
  • Airbnb
  • Coding & Algorithms
  • Software Engineer

Construct smallest number from I/D pattern

Company: Airbnb

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are given a string `pattern` consisting only of the characters: - `'I'` meaning the next digit is **increasing** - `'D'` meaning the next digit is **decreasing** Construct the **numerically smallest** positive integer (as a string) that satisfies the pattern using **distinct digits** from `1` to `9`. Formally, if `pattern` has length `n`, you must output a string `ans` of length `n + 1` such that for every `i`: - if `pattern[i] == 'I'`, then `ans[i] < ans[i+1]` - if `pattern[i] == 'D'`, then `ans[i] > ans[i+1]` Digits cannot repeat, and you may only use digits `'1'` through `'9'`. ## Input - `pattern`: string of length `n` where `1 <= n <= 8` ## Output - The lexicographically/numerically smallest valid number as a string. ## Example - `pattern = "IID"` → output could be `"1243"` (since `1<2<4>3`).

Quick Answer: This question evaluates a candidate's ability to reason about permutation constraints, sequence ordering, and combinatorial construction under digit-uniqueness and numeric-minimization requirements.

Related Interview Questions

  • Find Optimal Property Combination - Airbnb (medium)
  • Determine Exact Layover Booking - Airbnb (medium)
  • Solve Linked-List and Iterator Problems - Airbnb
  • Implement Text Layout and Query Parsing - Airbnb (easy)
  • Parse Query Parameters Into a Map - Airbnb (medium)
Airbnb logo
Airbnb
Feb 11, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
36
0
Coding Console
Loading...

Problem

You are given a string pattern consisting only of the characters:

  • 'I' meaning the next digit is increasing
  • 'D' meaning the next digit is decreasing

Construct the numerically smallest positive integer (as a string) that satisfies the pattern using distinct digits from 1 to 9.

Formally, if pattern has length n, you must output a string ans of length n + 1 such that for every i:

  • if pattern[i] == 'I' , then ans[i] < ans[i+1]
  • if pattern[i] == 'D' , then ans[i] > ans[i+1]

Digits cannot repeat, and you may only use digits '1' through '9'.

Input

  • pattern : string of length n where 1 <= n <= 8

Output

  • The lexicographically/numerically smallest valid number as a string.

Example

  • pattern = "IID" → output could be "1243" (since 1<2<4>3 ).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Airbnb•More Software Engineer•Airbnb Software Engineer•Airbnb 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.