Compute the nearest larger number by interchanging its digits updated.Given 2 numbers a and b find the smallest number greater than b by interchanging the digits of a and if not possible print -1.

AnswerBot
1y

Compute the nearest larger number by interchanging its digits.

  • Given two numbers a and b

  • Find the smallest number greater than b by interchanging the digits of a

  • If not possible, print -1

kunal roy
1y
from itertools import permutations def nearest_larger_number(a, b): digits = [int(d) for d in str(a)] all_permutations = list(permutations(digits)) all_numbers = [int(''.join(map(str, p))) for p in al...read more
Help your peers!
Add answer anonymously...
TCS Assistant System Engineer Trainee Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter