Reverse words in a given string (geeksforgeeks): Problem of the Day 29/01/2022

preview_player
Показать описание
@CodeChef @GeeksforGeeks @Leetcodes #leetcode #geeksforgeeks #adobe #amazon #microsoft #dailychallenge #technicalinterview #problemoftheday

Solution Code: Available in comment section

Given a String S, reverse the string without reversing its individual words. Words are separated by dots.
Рекомендации по теме
Комментарии
Автор

Solution Code:
class Solution
{
String reverseWords(String S)
{
ArrayList<Integer>al=new ArrayList<>();
al.add(0);
for(int i=0;i<S.length();i++)
{
if(S.charAt(i)=='.')
al.add(i);
}
al.add(S.length());
String ans="";
for(int i=al.size()-2;i>0;i--)
{
ans+=S.substring(al.get(i)+1, al.get(i+1));
ans+=".";
}
ans+=S.substring(al.get(0), al.get(1));
return ans;
}
}

viralSongsBollywood
Автор

Liked your explanation bhai.. string.split() nhi use kr skte kya?

alwaysSleepyBear
Автор

Bhaiya, Please explain question D from educational codeforces round 122

soniya_naskar