Determine if two strings/phrases are valid Anagrams | Study Algorithms

  Рет қаралды 6,199

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Пікірлер: 16
@anirudhv0062
@anirudhv0062 6 ай бұрын
In the Optimized code, I don't think we need to check for spaces. Since anagrams are supposed to be single words, if there are spaces the string, it will become a phrase instead of a word. Also if we check in the beginning if the strings are of equal length, there is no need for 2 for loops of bucket arrays. The code can be simplified to : class Solution { public boolean isAnagram(String s, String t) { if (s.length() != t.length()) return false; int counts = new int[26]; for (int i=0; i
@SatishSingh-eb5tq
@SatishSingh-eb5tq 4 ай бұрын
Why didn't you used HashMap to fill the values first with key and counter and then to decrement. Why to go for A-Z map?
@lalanabiridi8358
@lalanabiridi8358 11 ай бұрын
instead of bucket array we can use hashtable too right??? by removing spaces
@jritzeku
@jritzeku 9 ай бұрын
I took this approach: -remove all empty spaces first -early exit cond; if length dont equal -In first loop evaluated first string populated hash map with occurrence of each char. -In second loop, evaluated second string and decremented the count from map. If the count was at 1, i removed it from map. -Ultimately, at the end if the map is empty (length of 0), we found anagram.
@mai_aasim
@mai_aasim 9 ай бұрын
Thanks for helping
@eduardoignacioroblessosa6349
@eduardoignacioroblessosa6349 5 ай бұрын
brilliant as always
@nageshnimmala7366
@nageshnimmala7366 2 жыл бұрын
Can i get by using compareTo metheod?
@nageshnimmala7366
@nageshnimmala7366 2 жыл бұрын
One more request pls suggest me a book where I can understand advanced java and data structures and algorithms easily
@nikoo28
@nikoo28 2 жыл бұрын
If you check the link the video description, I do mention some resources :) Hope that helps
@nageshnimmala7366
@nageshnimmala7366 2 жыл бұрын
@@nikoo28 Yaa that's ok but i searched for that but it's very advanced one
@nageshnimmala7366
@nageshnimmala7366 2 жыл бұрын
Pls recommend me some good books to learn servelets, jsp, microservices
@nikoo28
@nikoo28 2 жыл бұрын
Have you tried the headfirst series? They are really easy to follow, have a lot of visuals and you will make projects too as you read along. Highly recommended :)
@pradeepella
@pradeepella 3 жыл бұрын
package javaprac; public class JavaPrac { public boolean anagram(String str1,String str2){ str1=str1.toLowerCase(); str2=str2.toLowerCase(); str1=str1.replace(" ", ""); str2=str2.replace(" ", ""); int[] arr=new int[26]; for(int i=0;i
@mr_funtor
@mr_funtor 7 ай бұрын
You looped 3 times. Shouldn't this be n^3?
@nikoo28
@nikoo28 7 ай бұрын
3 loops do not mean O(n^3)...3 nested loops will cause the time complexity to be n^3. 3 separate loops mean O(3 * n) = O(n)
@mr_funtor
@mr_funtor 7 ай бұрын
@@nikoo28 Alright. Thanks
Which One Is The Best - From Small To Giant #katebrush #shorts
00:17
How it feels when u walk through first class
00:52
Adam W
Рет қаралды 20 МЛН
Cool Parenting Gadget Against Mosquitos! 🦟👶
00:21
TheSoul Music Family
Рет қаралды 11 МЛН
Officer Rabbit is so bad. He made Luffy deaf. #funny #supersiblings #comedy
00:18
Funny superhero siblings
Рет қаралды 19 МЛН
ML Was Hard Until I Learned These 5 Secrets!
13:11
Boris Meinardus
Рет қаралды 321 М.
Valid Anagram - Leetcode 242 - Python
12:01
NeetCode
Рет қаралды 550 М.
Leetcode 46. Permutations : Introduction to backtracking
10:06
ComputerBread
Рет қаралды 99 М.
Solving Wordle using information theory
30:38
3Blue1Brown
Рет қаралды 10 МЛН
L11. Valid Parenthesis String | Multiple Approaches
26:09
take U forward
Рет қаралды 38 М.
LeetCode 242. Valid Anagram Solution Explained - Java
6:23
Nick White
Рет қаралды 47 М.
5 Simple Steps for Solving Dynamic Programming Problems
21:27
Reducible
Рет қаралды 1 МЛН
Check if two strings are anagrams
8:50
Techdose
Рет қаралды 71 М.
Which One Is The Best - From Small To Giant #katebrush #shorts
00:17