Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

code javascript: Find the next integer with no two identical consecutive digits. Task description You are given a positive integer N . Your task is

code javascript: Find the next integer with no two identical consecutive digits.
Task description
You are given a positive integer N. Your task is to find the smallest integer greater than N that does not contain two identical consecutive digits.
For example, given N =1765, the smallest integer greater than N is 1766. However, in 1766 the last two digits are identical. The next integer, 1767, does not contain two identical consecutive digits, and is the smallest integer greater than 1765 that fulfils the condition. Note that the second and fourth digits in 1767 can both be 7 as they are not consecutive.
Write a function:
function solution(N);
that, given an integer N, returns the smallest integer gre
ater than N that does not contain two identical consecutive digits.
Examples:
1. Given N =55, the function should return 56. It is the smallest integer greater than 55 and it does not contain two consecutive digits that are the same.
2. Given N =1765, the function should return 1767, as explained above.
3. Given N =98, the answer should be 101. Both 99 and 100 contain two identical consecutive digits, but 101 does not.
4. Given N =44432, the answer should be 45010.
5. Given N =3298, the answer should be 3401.
Write an efficient algorithm for the following assumptions:
N is an integer within the range [1..1,000,000,000].

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions