Live Coding Challenge | Episode 3 | Problem Solving with Turing

preview_player
Показать описание
The third episode of "Problem Solving with Turing", takes you through a different problem and dissects it step-by-step to help you understand the correct approach to solving coding problems that will help you ace coding challenges and crack technical interviews with ease.

Become a Turing software developer today.

Рекомендации по теме
Комментарии
Автор

Why not just turn it to a string, put it in a list and then reverse the list?

Fanaro
Автор

You could just convert to string and split, check if the first element is '-'. If it is, reverse the list, join, convert to number and multiply by -1 and return the product else just return without multiplying by -1

barthsparks
Автор

I think the part that checks for the overflow is kinda wrong cuz it relies on integers outside the 32-bit integer range

JuanSB
Автор

Temesgen from Ethiopia using C#
int ReverseInt(int a)
{
int sign = 1;
if (a < 0)
sign = -1;
a = a * sign;
int result = 0;
while (a > 0)
{
result = result * 10 + a % 10;
a = a / 10;
}
return result * sign;
}

tmstechschool
Автор

How can this be solved on JavaScript: Imagine a circular jogging track with several rest points, labeled from 0 to n-1. the distance between each rest point is known and record in an array called distance [], where distance [i] shows the distance between point a and point (i+1)% n. a person wants to find the minimum distance between two chosen rest points, start and destination, on the circular route, while being able to travel in both directions, clockwise and counterclockwise.

KateNelson-jygz
Автор

Jose, the error you got with the ranges is because of the use of parseInt, you're going above/below the valid numbers for integers, if you use Math.floor, that will do the trick for any number.
Also, you forgot to cover the negatives.
Here's a solution.

function reverseInteger(number) {
let numberToConvert = Math.abs(number)
let result = 0
while (numberToConvert > 0) {
const rest = numberToConvert % 10
numberToConvert = Math.floor(numberToConvert / 10)
result = (result * 10) + rest
}

if (result < (2 ** 31 * -1)) return 0
if (result > (2 ** 31 - 1)) return 0

return (number < 0) ? -result: result
}

BraulioRojas-tfpv
Автор

Make you made noise just present in peaceful environment

ameerhamza
Автор

Haven't compiled it but possible C# solution
public int ReverseInteger(int num)
{
lstNums = new
int rem, coffeicinet;
coffeicinet=num/10;
rem=num%10;
int exponent=0;
int returnedNum=0;
while(coffeicinet>=10)
{
exponent++;
lstNums.Add(rem);
rem=coffeicinet%10;
coffeicinet=coffeicinet/10;
}
lstNums.Add(coffeicinet);

for(int i=0;i<lstNums.Count && exponent>=0;i++, exponent--)
{
returnedNum+=lstNums[i]*Math.Pow(10, exponent);
}

return returnedNum;
}

birukabel
Автор

please add Kotlin language your coding challenge.

hikmetqedirov
Автор

I solved it like so, * (Math.abs(num) === num ? +1 : -1)

NeniEmSu