Simplify Path | Leetcode - 71 | META | Explanation ➕ Live Coding

preview_player
Показать описание
This is the 10th Video on our Stack Playlist.
In this video we will try to solve a very popular but interview centric problem "Simplify Path" (Leetcode-71).

We will do live coding after explanation and see if we are able to pass all the test cases.

Problem Name : Simplify Path
Company Tags : META

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
#interviewpreparation #interview_ds_algo #hinglish
Рекомендации по теме
Комментарии
Автор

I always learn something new and interesting when I watch your videos, thank you for sharing your expertise with us!

MyCodingDiary
Автор

Please keep making these videos. They are very helpful ✨

userfg
Автор

I daily spend time in watching videos but I video is more than 40mins I skip 😅😅 which made me lose some concepts but explanation was always top notch

prudhvirajmacherla
Автор

From this video, i learnt about tokenization and how to implement it and found an another solution using tokenization for this problem :)
Thanks bhaiya 🤗

amanbalhara
Автор

after spending hours was able to come up with the solution after watching till 3.42...that . means continue and .. means pop
Many thanks!

samridhshubham
Автор

Java Code:


Approach 1: (STACK)

import java.util.*;
class Solution {
public String simplifyPath(String path) {

Stack<String> stack = new Stack<>();
StringTokenizer st=new StringTokenizer(path, "/");
while(st.hasMoreTokens())
{
String s=st.nextToken();
System.out.println(s);
if(s.equals(" ")|| s.equals("."))
continue;
else if(s.equals(".."))
{
if(!stack.isEmpty())
stack.pop();
}
else
stack.push(s);
}
String ans="";
for(String str:stack)
{
ans=ans+"/"+str;
}
if(ans.equals("")) return "/";
return ans;
}
}


Approach 2:(ARRAYLIST)

import java.util.*;
class Solution {
public String simplifyPath(String path) {

ArrayList<String> list=new ArrayList<>();
StringTokenizer st=new StringTokenizer(path, "/");
while(st.hasMoreTokens())
{
String s=st.nextToken();
System.out.println(s);
if(s.equals(" ")|| s.equals("."))
continue;
else if(s.equals(".."))
{
if(list.size()>0)
list.remove(list.size()-1);
}
else
list.add(s);
}
String ans="";
for(String str:list)
{
ans=ans+"/"+str;
}
if(ans.equals("")) return "/";
return ans;

}
}

utsabkundu
Автор

tu banda great hai but mila thoda late hai :)

rohitsoni
Автор

bhya plz ek bar LC 2104 "Sum of Subarray Ranges" bhi upload kar dijiye..plz

abhishekverma
Автор

Bro, I wanted to ask how many more videos will come in the graph playlist and the expected time until completion.

divyanshsagar
Автор

ye question first time kese solve ho skta h kisi se

shourabhjamwal
Автор

Again my comment is getting auto removed

JJ-tpdd