PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Maximize number with one digit swap

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's skill in digit and string manipulation, greedy algorithm design, and implementation of linear-time algorithms. It is commonly asked in the Coding & Algorithms domain to assess algorithmic efficiency, practical problem-solving with edge-case handling, and the application of greedy strategies as a practical algorithmic task rather than a purely conceptual exercise.

  • Medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Maximize number with one digit swap

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

Given a non-negative integer n (as an int or string), perform at most one swap of two digits to produce the maximum possible value. Return the resulting integer. Design an O(L) algorithm (L = number of digits) using last-occurrence tracking of digits and scan from most significant to least significant. Include an early exit when the current digit is already the largest available to its right and no better swap exists.

Quick Answer: This question evaluates a candidate's skill in digit and string manipulation, greedy algorithm design, and implementation of linear-time algorithms. It is commonly asked in the Coding & Algorithms domain to assess algorithmic efficiency, practical problem-solving with edge-case handling, and the application of greedy strategies as a practical algorithmic task rather than a purely conceptual exercise.

Related Interview Questions

  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)
  • Solve a Key-Door Corridor Maze - Meta (medium)
  • Solve Array Merge and Parentheses Cleanup - Meta (medium)
Meta logo
Meta
Jul 15, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
2
0

Given a non-negative integer n (as an int or string), perform at most one swap of two digits to produce the maximum possible value. Return the resulting integer. Design an O(L) algorithm (L = number of digits) using last-occurrence tracking of digits and scan from most significant to least significant. Include an early exit when the current digit is already the largest available to its right and no better swap exists.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

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

Master your tech interviews with 8,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.