Easy Amazon Interview Question | Coding | LeetCode | Arrays

preview_player
Показать описание
Amazon coding interview question for new grads #coding #python #leetcode #shorts
Рекомендации по теме
Комментарии
Автор

or we can create a hashmap and check if s[i] is > 0 then s[i] -- ; and continue, else return false
o(n) time complexity
but more memory used

Raghav_Kapoor_
Автор

there’s a way to make it better where if you ever encounter the parent character u store it and then continue to search the next substring so “ABABACD” and u r searching “ABACD” then it will check “A” = “A”, “AB” = “AB” (parent is A), “ABA” = “ABA” (parents are A B) (Current character “A” is a parent so store the index 2), “ABAB” != “ABAC” (start considering parent indices. go to index 2 and start from there), “AB” = “AB”, “ABA” = “ABA”, “ABAC” = “ABAC.

notjin
Автор

This breaks if you don’t check length first and if you move the bottom pointer J first.

enknot
Автор

bool isSubsequence(string s, string t) {
        int last_index = -1 ;
        for(int i = 0 ; i < s.size() ; i++){
            int flag = 0 ;
            for(int j = last_index+1 ; j < t.size() ; j++){
                if(s[i] == t[j]){
                    flag = 1 ;
                    last_index = j ;
                    break;
                }
            }
            if(flag == 0){
                return false ;
            }
        }
       return true;
    }

Raghav_Kapoor_
Автор

How about create an array that will store all correct answers then …

Nextgameisbetter
Автор

Hi
.plz make more vids not just shorts covering more leetcode problems, topic wise..like two pointers, easy ones first ..which should cover all variations on that topic ..You are really good in explaining stuff in simple terms.. and I dont usually comment so..

adiy
join shbcf.ru