Skip to main content
Tweeted twitter.com/StackCodeGolf/status/1196805478396940294
Added path-finding tag and note on 0-indexing.
Source Link
Jitse
  • 7.7k
  • 3
  • 19
  • 43

In this challenge, you are given a number x. You have to find the minimum number of steps required to reach x from 1. At a particular point, you have two choices:

1) Increment the number by 1.

2) Reverse the integer (remove leading zeros after reversing)

Input: n=42    
Output: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>41>42 **(15 steps)**

The minimum steps to reach 42 from 1 is 15. This can be achieved if we increment numbers by 1 from 1 to 14 (13 steps). After reaching 14 we can reverse the number which will give us 41 (1 step). From 41 we can increment number by 1 to reach 42(1 step). Hence the total number is 15 steps, which is then the minimum.

Note that if we reverse the number after reaching 12 or 13, we will not get the minimum steps.

1>2>3>4>5>6>7>8>9>10>11>12>21>22>23>32>33>34>35>36>37>38>39>40>41>42 (25 steps)

Input: n=16
Output: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>15>16 **(15 steps)**

In this case we have to increment the numbers until we get 16, which will give us a minimum of 15 steps.

Note: Starting from 0 is also allowed, which will increase all output by 1.

In this challenge, you are given a number x. You have to find the minimum number of steps required to reach x from 1. At a particular point, you have two choices:

1) Increment the number by 1.

2) Reverse the integer (remove leading zeros after reversing)

Input: n=42    
Output: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>41>42 **(15 steps)**

The minimum steps to reach 42 from 1 is 15. This can be achieved if we increment numbers by 1 from 1 to 14 (13 steps). After reaching 14 we can reverse the number which will give us 41 (1 step). From 41 we can increment number by 1 to reach 42(1 step). Hence the total number is 15 steps, which is then the minimum.

Note that if we reverse the number after reaching 12 or 13, we will not get the minimum steps.

1>2>3>4>5>6>7>8>9>10>11>12>21>22>23>32>33>34>35>36>37>38>39>40>41>42 (25 steps)

Input: n=16
Output: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>15>16 **(15 steps)**

In this case we have to increment the numbers until we get 16, which will give us a minimum of 15 steps.

In this challenge, you are given a number x. You have to find the minimum number of steps required to reach x from 1. At a particular point, you have two choices:

1) Increment the number by 1.

2) Reverse the integer (remove leading zeros after reversing)

Input: n=42    
Output: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>41>42 **(15 steps)**

The minimum steps to reach 42 from 1 is 15. This can be achieved if we increment numbers by 1 from 1 to 14 (13 steps). After reaching 14 we can reverse the number which will give us 41 (1 step). From 41 we can increment number by 1 to reach 42(1 step). Hence the total number is 15 steps, which is then the minimum.

Note that if we reverse the number after reaching 12 or 13, we will not get the minimum steps.

1>2>3>4>5>6>7>8>9>10>11>12>21>22>23>32>33>34>35>36>37>38>39>40>41>42 (25 steps)

Input: n=16
Output: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>15>16 **(15 steps)**

In this case we have to increment the numbers until we get 16, which will give us a minimum of 15 steps.

Note: Starting from 0 is also allowed, which will increase all output by 1.

reach Reach the number in minimum steps

In this challenge, you are given a number x. youYou have to find the minimum number of steps required to reach x from 1. At At a particular point, you have two choices:

1) incrementIncrement the number by 1.

2) reverseReverse the integer (remove leading zeros after reversing)

eg: n=42

sol: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>41>42 (15 steps)

Input: n=42    
Output: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>41>42 **(15 steps)**

The minimum steps to reach 42 from 1 is 15. This can be achieved if we increment numbers by 1 from 1 to 14 (13 steps). After reaching 14 we can reverse the number which will give us 41 (1 step). From 41 we can increment number by 1 to reach 42(1 step). henceHence the total number is 15 steps, which is then the minimum.

Note that if we reverse the number after reaching 12 or 13, we will not get the minimum steps.

1>2>3>4>5>6>7>8>9>10>11>12>21>22>23>32>33>34>35>36>37>38>39>40>41>42 (25 steps)

eg: n=16

sol: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>15>16 (15 steps)

Input: n=16
Output: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>15>16 **(15 steps)**

In this case we have to increment the numbers tilluntil we get 16, which will give us thea minimum of 15 steps.

reach the number in minimum steps

In this challenge, you are given a number x. you have to find the minimum number of steps required to reach x from 1. At a particular point, you have two choices

1) increment the number by 1

2) reverse the integer (remove leading zeros after reversing)

eg: n=42

sol: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>41>42 (15 steps)

The minimum steps to reach 42 from 1 is 15. This can be achieved if we increment numbers by 1 from 1 to 14 (13 steps). After reaching 14 we can reverse the number which will give us 41 (1 step). From 41 we can increment number by 1 to reach 42(1 step). hence total 15 steps which is then minimum

Note that if we reverse the number after reaching 12 or 13, we will not get the minimum steps

1>2>3>4>5>6>7>8>9>10>11>12>21>22>23>32>33>34>35>36>37>38>39>40>41>42 (25 steps)

eg: n=16

sol: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>15>16 (15 steps)

In this case we have to increment the numbers till 16 which will give us the minimum of 15 steps.

Reach the number in minimum steps

In this challenge, you are given a number x. You have to find the minimum number of steps required to reach x from 1. At a particular point, you have two choices:

1) Increment the number by 1.

2) Reverse the integer (remove leading zeros after reversing)

Input: n=42    
Output: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>41>42 **(15 steps)**

The minimum steps to reach 42 from 1 is 15. This can be achieved if we increment numbers by 1 from 1 to 14 (13 steps). After reaching 14 we can reverse the number which will give us 41 (1 step). From 41 we can increment number by 1 to reach 42(1 step). Hence the total number is 15 steps, which is then the minimum.

Note that if we reverse the number after reaching 12 or 13, we will not get the minimum steps.

1>2>3>4>5>6>7>8>9>10>11>12>21>22>23>32>33>34>35>36>37>38>39>40>41>42 (25 steps)

Input: n=16
Output: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>15>16 **(15 steps)**

In this case we have to increment the numbers until we get 16, which will give us a minimum of 15 steps.

deleted 1 character in body
Source Link
adam
  • 179
  • 5

In this challenge, you are given a number x. you have to find the minimum number of steps required to reach x from 1. At a particular point, you have two choices

1) increment the number by 1

2) reverse the integer (remove leading digitszeros after reversing)

eg: n=42

sol: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>41>42 (15 steps)

The minimum steps to reach 42 from 1 is 15. This can be achieved if we increment numbers by 1 from 1 to 14 (13 steps). After reaching 14 we can reverse the number which will give us 41 (1 step). From 41 we can increment number by 1 to reach 42(1 step). hence total 15 steps which is then minimum

Note that if we reverse the number after reaching 12 or 13, we will not get the minimum steps

1>2>3>4>5>6>7>8>9>10>11>12>21>22>23>32>33>34>35>36>37>38>39>40>41>42 (25 steps)

eg: n=16

sol: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>15>16 (15 steps)

In this case we have to increment the numbers till 16 which will give us the minimum of 15 steps.

In this challenge, you are given a number x. you have to find the minimum number of steps required to reach x from 1. At a particular point, you have two choices

1) increment the number by 1

2) reverse the integer (remove leading digits after reversing)

eg: n=42

sol: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>41>42 (15 steps)

The minimum steps to reach 42 from 1 is 15. This can be achieved if we increment numbers by 1 from 1 to 14 (13 steps). After reaching 14 we can reverse the number which will give us 41 (1 step). From 41 we can increment number by 1 to reach 42(1 step). hence total 15 steps which is then minimum

Note that if we reverse the number after reaching 12 or 13, we will not get the minimum steps

1>2>3>4>5>6>7>8>9>10>11>12>21>22>23>32>33>34>35>36>37>38>39>40>41>42 (25 steps)

eg: n=16

sol: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>15>16 (15 steps)

In this case we have to increment the numbers till 16 which will give us the minimum of 15 steps.

In this challenge, you are given a number x. you have to find the minimum number of steps required to reach x from 1. At a particular point, you have two choices

1) increment the number by 1

2) reverse the integer (remove leading zeros after reversing)

eg: n=42

sol: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>41>42 (15 steps)

The minimum steps to reach 42 from 1 is 15. This can be achieved if we increment numbers by 1 from 1 to 14 (13 steps). After reaching 14 we can reverse the number which will give us 41 (1 step). From 41 we can increment number by 1 to reach 42(1 step). hence total 15 steps which is then minimum

Note that if we reverse the number after reaching 12 or 13, we will not get the minimum steps

1>2>3>4>5>6>7>8>9>10>11>12>21>22>23>32>33>34>35>36>37>38>39>40>41>42 (25 steps)

eg: n=16

sol: 1>2>3>4>5>6>7>8>9>10>11>12>13>14>15>16 (15 steps)

In this case we have to increment the numbers till 16 which will give us the minimum of 15 steps.

Became Hot Network Question
edited tags
Link
The Fifth Marshal
  • 6.3k
  • 1
  • 25
  • 44
Loading
added 583 characters in body
Source Link
adam
  • 179
  • 5
Loading
deleted 1 character in body
Source Link
adam
  • 179
  • 5
Loading
Source Link
adam
  • 179
  • 5
Loading