791. Custom Sort String | leetcode daily challenge | DSA | Shashwat Tiwari Hindi
HTML-код
- Опубликовано: 22 авг 2024
- Problem Name:
791. Custom Sort String
Problem Statement:
You are given two strings order and s. All the characters of order are unique and were sorted in some custom order previously.
Permute the characters of s so that they match the order that order was sorted. More specifically, if a character x occurs before a character y in order, then x should occur before y in the permuted string.
Return any permutation of s that satisfies this property.
Problem link:
www.geeksforge...
Java Plus DSA Placement Course Playlist:
• Java and DSA Course Pl...
Java Plus DSA Sheet:
docs.google.co...
Notes:
github.com/Tiw...
Telegram Link:
shashwattiwari...
Ultimate Recursion Series Playlist:
• Recursion and Backtrac...
Instagram Handle: (@shashwat_tiwari_st)
shashwattiwari...
Samsung Interview Experience:
• I cracked Samsung | SR...
Company Tags:
Facebook | Amazon | Microsoft | Netflix | Google | LinkedIn | Pega Systems | VMware | Adobe | Samsung
Timestamp:
0:00 - Introduction
#ShashwatTiwari #coding #problemsolving Leetcode,Faang Interviews,Fanng,maang,faang interview Problems,Leetcode by Shashwat Tiwari,Maang Interviews,Leetcode Shashwat, Leetcode 791, Leetcode 791 by Shashwat tiwari,Custom Sort String ,791. Custom Sort String ,791. Custom Sort String,Custom Sort String
You are doing great..and also very good teacher.
following you since last 10 days great efforts sir ❤❤❤
Salute to your dedication Bhaiya
Thank you sir
Thank You Bhaiya for the beautiful contents :)
simple and easy sol
public String customSortString(String order, String s) {
int [] cnt = new int[26];
for (char c : s.toCharArray()) {
cnt[c - 'a']++;
}
StringBuilder sb = new StringBuilder();
for (char c : order.toCharArray()) {
while (cnt[c - 'a'] > 0) {
sb.append(c);
cnt[c - 'a']--;
}
}
for (int i = 0; i < 26; i++) {
while (cnt[i] > 0) {
sb.append((char)('a' + i));
cnt[i]--;
}
}
return sb.toString();
}
I am third one❤❤❤😂😂
pls koi toposort se krke dedo
bhaiya why are we using entryset here rather than keySet
No special reason. KeySet bhi use kr skte ho
😋 *promo sm*