Find the Sequence of Strings Appeared on the Screen
Prashant Mishra

Prashant Mishra @prashantrmishra

About: There is always a price for those who persevere.

Location:
India
Joined:
Jul 2, 2022

Find the Sequence of Strings Appeared on the Screen

Publish Date: Oct 20 '24
0 0
class Solution {
    public List<String> stringSequence(String target) {
        List<String> list  = new ArrayList<>();
        StringBuilder sb = new StringBuilder();
        for(char c : target.toCharArray()){
            if(list.size()!=0){
                sb.append(list.get(list.size()-1));
            }
            sb.append('a');
            list.add(sb.toString());
            for(char i = 'a'+1;i<=c;i++){
                sb.deleteCharAt(sb.length()-1);
                sb.append(i);
                list.add(sb.toString());
            }
            sb.setLength(0);
        }
        return list;
    }
}
Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment