🔥 Welcome to Ashok IT..!! 👉 Register Here For Online Training : bit.ly/4dBYJbX 👉 Follow us in Instagram : bit.ly/3jzEKl8 👉 Follow Us in WhatsApp : bit.ly/49wCWje 👉 Visit Our Website : ashokit.in/
public class practicee { public static void main(String args[]) { String s="AABCDBE"; int count=0; char[] k =s.toCharArray(); for (int i = 0; i < k.length; i++) { for (int j = 0; j < k.length; j++) { if (k[i]==k[j]) { count++; }
} if (count==1) { System.out.println(k[i]); break; } count=0; } } } this is my approach
After finding frequency for every element then take another loop iterate thourgh loop index from 0 to string.length Then for each character check in the map wheather that character has 1 or not
I don't think j=i+1 would work because in that case first iteration A and A would be compared in second iteration A and b would be compared and thus compiler would declare A as the first non repeating character.I am also not sure.
@@krishkhemani96 if we take j = i+1 then it will consider the last duplicate character as the first non-repeating character for eg It will consider 'A' of index 1 as a non-repeating character.
using this collection approach it won't give correct output , if the non repeated occurs at the first position , for example input = "kaabcdbe" output should be k but it would give c.
I don't think j=i+1 would work because in that case first iteration A and A would be compared in second iteration A and b would be compared and thus compiler would declare A as the first non repeating character.I am also not sure.
🔥 Welcome to Ashok IT..!!
👉 Register Here For Online Training : bit.ly/4dBYJbX
👉 Follow us in Instagram : bit.ly/3jzEKl8
👉 Follow Us in WhatsApp : bit.ly/49wCWje
👉 Visit Our Website : ashokit.in/
Ur way of explaining or teaching is excellent 👌😉bro superb 👌👍👏, nobody is there ...
public class practicee {
public static void main(String args[])
{
String s="AABCDBE";
int count=0;
char[] k =s.toCharArray();
for (int i = 0; i < k.length; i++) {
for (int j = 0; j < k.length; j++) {
if (k[i]==k[j]) {
count++;
}
}
if (count==1) {
System.out.println(k[i]);
break;
}
count=0;
}
}
}
this is my approach
Collection approach is the best ❤
Thankyou so much.. 🔥 Please follow us in WhatsApp channel : bit.ly/49wCWje
Shouldn't the map be LinkedHashMap so that it maintains the insertion order to correctly identify first non-repeated character?
Yes it should be😊
Thanks Bro. Your explanation is super cool.
Thank you Sir.
Thankyou so much..
Excellent . Thanks sir
In hashMap the insertion order is not maintain, how can you be sure it will give your the First Non Repeated Char boss ????
please contact our admin team : +91 9985396677
After finding frequency for every element then take another loop iterate thourgh loop index from 0 to string.length
Then for each character check in the map wheather that character has 1 or not
Very nice explanation
Thanks for liking
Really superb
Tq Ashok bro
My approach :
String unique = "AABDCE";
for (int i = 0; i < unique.length(); i++) {
for (int j = i+1; j < unique.length(); j++) {
if(unique.charAt(i) != unique.charAt(j)) {
System.out.println("1st non repeating char is : "+unique.charAt(j));
return;
}
}
}
🔥 Please follow us in WhatsApp channel : bit.ly/49wCWje
It won't work for all the cases it will print all the characters from given string expect
You can use j=i+1
same doubt
I don't think j=i+1 would work because in that case first iteration A and A would be compared in second iteration A and b would be compared and thus compiler would declare A as the first non repeating character.I am also not sure.
@@krishkhemani96 if we take j = i+1 then it will consider the last duplicate character as the first non-repeating character for eg It will consider 'A' of index 1 as a non-repeating character.
using this collection approach it won't give correct output , if the non repeated occurs at the first position , for example input = "kaabcdbe" output should be k but it would give c.
Using index Of method?
It is coming last non repeated char we need first non repeated characters
Could u correct the code thro hashmap
Cant use HashMap here.
🔥 Please follow us in WhatsApp channel : bit.ly/49wCWje
Your coding still needs some polishing, first approach you should have used j=i+1 and the second approach you should have used LinkedHashMap.
Yeass bro and the hashmap does not maintain insertion order right? How he got the answer bro..!
@@anbuv.g.k495 It will work 90% of the time, but in production setting you'll face reality.
I don't think j=i+1 would work because in that case first iteration A and A would be compared in second iteration A and b would be compared and thus compiler would declare A as the first non repeating character.I am also not sure.