 Good morning guys. I hope everyone is doing great and welcome back to a channel. So today in this video I'll be sharing you one of the interview questions that I have faced couple of years ago and This is the question and answer you can see on the screen So the input that was given to me was list of strings that contains date days of the week The output should be in the sorted way so if you see here all the days of the week are present in the format of string and The output should be like this Sunday Monday Tuesday Wednesday Thursday Friday Saturday And this if you see the second sample input and output there are few days that are missing and the output should also does on the output should also That those days are missing. So if you see Monday Friday Tuesday, which Sunday the output would be Sunday Monday Tuesday Friday as Wednesday Thursday Saturday has not present in the input. So the same applies here. They should not be present in the Output as well. Similarly the sample third sample as well So the reason for sharing this question was this is actually real-time scenario that We like the project for which I was in getting interviewed was facing this issue So if you see this was that that was an healthcare related project So the screen was like this so name address and appointment day So here they were having like Sunday Monday Tuesday any day all the days So when they click on the sort buttons that should get sorted the point based on the appointment day the Names and everything should get sorted on the page. So they were really facing this issue here So they have implemented it using if it's so later on I have changed it using Comparator and that is the same solution that I am going to share here as well And one more reason of sharing this question is recently when I was interviewing few guys I was just expecting the approach how The interviewer how the candidate would see so most of like out of 10 15 guys No one was able to give the solution to be honest even the approach everyone whenever they see this Monday Friday Saturday Sunday, they try to convert it into date. So that is the That is where they were failing like they were trying to convert it to today date using Java time API and they were trying to sort it and believe me even on the Google You will not find be able to find a solution because out of 15 guys I have asked five guys to take help from Google to give the solution even they were unable to give the So approach as approach itself. So thought of sharing this so I have already written the comparator as well So let us see I have created all the inputs like four inputs So first input is same as the sample whatever sample I was discussed Similarly second and I'm having few sys outs and directly I want to run this So let us run So if you see here So this is the sample input. I printed on the first 10 and this is the output So the day should sort from Sunday and the last day should be Saturday So this is the output that we got similarly for the second input and Output there are few days missing here. There are few days missing here in the sample input three and four So what logic I have written in the week days? Comparator I am going to share that. So what I have did here is I have created one one map here So in that map, this is the way we I have created the map The string as a key and one integer as a value. So for Sunday, I have given zero for Monday I have given one for Tuesday to Similarly till Saturday It is six. So in the compare method of the comparator This is the logic that I have given so week map dot get of O one So this is a string basically it could be Sunday Monday anything So this should that will return a number an integer Similarly, so basically even though I am passing the string. I'm internally Comparing the integers here. So this is how I Refine refactor the middle. So earlier they were having if else if else if else so they were having one Like what I can say sample thing if you say if they were checking the list. So we'd like this if Sunday What is the least sample if you can take sample for dot contains So they're writing like this If they if it contains then in the output some output list, they were adding manually again Like this Sunday, sorry, sorry for spelling mistakes on Sunday. So similarly for all the seven days They were adding it. So I have refactored it to That comparator. So there is one more approach That we can follow here that is using switch switch case because Java now supports switch case with string. So now let us see how we can Achieve it. So to save some time. I have already created the method and I have created a method called short date So I am passing the input which takes an input of this So here is the switch case logic that I have written it is similar to If else as so instead of if we're going with string as what is switch case? So every day every time it Compares the input here is the fur loop and as fur loop I'm using so it will convert it will add that into the list If the day is present then it will add if it is not present it won't add So that is how we can do it with using switch case as well So these are the two ways that We can add three ways that we can do like one is switch case one is if it's and one is using Comparator. So that is what I wanted to share as part of this video. So if you like the video you can Share it to other platforms as well You can comment it out if you know any other approach in giving a solution for this type of problem Please do comment out in the comment section because even It would be a learning for us as well So if you haven't subscribed our channel, you can feel free to subscribe Our channel to get the latest interview experiences of different videos as you can see we have already We have already started working on tip co interview process This is shared by one of our subscriber friends. So very soon you can expect a video on this as well and If you want to contribute us you can use the Amazon affiliation link that is present in the description of the video And if you are watching this video for the first time you can visit our channel and see all the videos that we have already Posted and you can get benefited out of it. There are very good videos Like more than 100 videos we have already shared and that will definitely help you out Interacting many of the interviews. So we have started working on you can see QA interview questions as well. So very soon we'll be posting it on those things as well and There are few devops people that we are contacting and very soon we'll be posting the interview questions on devops as well so stay tuned to get So Subscribers to get to catch all the updates of the channel and thank you for watching