Fraction to Recurring Decimal (Leetcode 166) Solution | Hashmap Interview Question Playlist

preview_player
Показать описание

NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we discuss the fraction to recurring decimal problem using hashmaps in java. In this problem,

1. You are given two numbers which represent the numerator and denominator of a fraction.
2. You have to convert this fraction into a decimal.
3. If the decimals are repeating recursively, then you have to put the recurring sequence inside a bracket.

#hashmap #datastructure #algorithm

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

step by step improving solution as per requirement is awesome way of explanation, thank u sir j❤

ChristForAll-
Автор

sir gaate rahiye acha lgta hai. jb bhi question solve hota hai ya aap gaate ho to mza aa jata hai.

lifegood
Автор

fails for cases like these
-1 numerator
-2147483648 denominator
for this use long

harshdeepsinghful
Автор

when i first came, i thought i by mistake clicked on indian idol video, but wait, then i realised, there no neha kurkur crying in corner

GauravThinks
Автор

pepcoding== best dsa resources, under rated asf

sakshamp
Автор

Thank you sir, for such an intuitive explanation

anjanab
Автор

Starting k 5 second dekhar thoda darr gya ki sir ka classical music sikhane ka video bi aa gya kya..😂😂😂 On serious note thank you sir for you efforts. Hope your pepcoding become super duper success.. all the best.

CuteDeveloper
Автор

Kya sahi start kiya hain aapne video ka..:)

jollysrivastava
Автор

boolean flag = (n < 0) ^ (d < 0);
long nr = Math.abs((long)n);
long dr = Math.abs((long)d); forr negative nos

amCoder
Автор

what a voice what a explanation best teacher

aryanmittal
Автор

Sir, Mazza aagya aapka 0:00 Gaana sun kar !! Padhate toh aap ho hi tagda

adarshsharmanit
Автор

Mazaa aa gaya, kya awaaj hai sir ki ek number sir. Aise hi kuch gunguna diya kariye bahut sukoon milta hai sunke

shang_chi
Автор

The way you explain is fantastic. Keep it up :)

amar
Автор

for leetcode question, put these line on top of your code

if ((numerator < 0 && denominator > 0) || (numerator > 0 && denominator < 0))
ans.append("-");
long num = (long) Math.abs((long)numerator);
long den = (long) Math.abs((long)denominator);

deepak
Автор

for leetcode handled negative and long int values
class Solution {
public String fractionToDecimal(int numerator, int denominator) {
if(numerator== 0){
return "0";
}
boolean neg = (numerator < 0) ^ (denominator < 0);
long num = Math.abs((long)numerator);
long den = Math.abs((long)denominator);
long quotient = num/den;
long remainder = num % den;
StringBuilder sb = new StringBuilder();
if(neg){
sb.append('-');
}
sb.append(quotient);
if(remainder==0){
return sb.toString();
}
else{
sb.append('.');
Map<Long, Integer> map = new HashMap<>();
while(remainder!=0){

int pos = map.get(remainder);
sb.insert(pos, '(');
sb.append(')');
break;
}
map.put(remainder, sb.length());
remainder = remainder*10;
quotient = remainder/den;
remainder = remainder%den;
sb.append(quotient);
}
}
return sb.toString();
}
}

setiyakitchen
Автор

very lovely song . I think you have heard from Junaid Ashgar.

Sunny-qqun
Автор

what a start sir....mai apne pure family se subscribe karwa dunga jo programming jaanta v nahi hai agar aap ek arijit singh ka song gaaoge tab..just a request..

abhisheksrivastava
Автор

Yaar bhai bhut bhut dhanyawaad... Mst smjhaya

RishabhRJ
Автор

Best explaination....I thought ki sab coding karane vale log logic sai step by step kyu nhi smja pate...but the way you taught is

kdoxfkck
Автор

badiya video bhai, full desi like study. Keep it up

iknoorsingh