for bothsolutions we can add a condition to whether the given string has 26 characters and if not we can return false. if(s.length() < 26) return false; a small optimisation.
The ASCII value of A is 97 if we subract with any other character, we can get its actual number count, here it is used to store count in array so he used 97, we can also use 96 generally eg: a=97, if we subract b-97, we get 1,ie. 98-97=1
Exactly evlo memory store aagum nu paatha 26 units of memory. Aana complexity nu namma yosikkura apa proportional ah yosippom, so 2N nu irrunthalum O(N) nu than solluvom we'll drop the coefficient always. Inga input string oda size ennvaa irrunthalum namma use panra array oda size is always 26 , constant. So constant space na namma O(1) nu than solluvom, as we drop than coefficient in calculating complexity.
for bothsolutions we can add a condition to whether the given string has 26 characters and if not we can return false.
if(s.length() < 26) return false;
a small optimisation.
Bro yeepdi 97 subtraction panna index kedaikuthu please sollunga
The ASCII value of A is 97
if we subract with any other character, we can get its actual number count, here it is used to store count in array so he used 97, we can also use 96 generally
eg: a=97, if we subract b-97, we get 1,ie. 98-97=1
O(26) thana?
A to Z vara thana store agum
Exactly evlo memory store aagum nu paatha 26 units of memory. Aana complexity nu namma yosikkura apa proportional ah yosippom, so 2N nu irrunthalum O(N) nu than solluvom we'll drop the coefficient always.
Inga input string oda size ennvaa irrunthalum namma use panra array oda size is always 26 , constant.
So constant space na namma O(1) nu than solluvom, as we drop than coefficient in calculating complexity.
import java.util.Scanner;
import java.util.Arrays;
public class pangram {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String nstr = str.replaceAll("\\s", "").toLowerCase();
char[] arr1 = nstr.toCharArray();
Arrays.sort(arr1);
char[] arr = new char[26];
for (int i = 0; i < 26; i++) {
arr[i] = (char) ('a' + i);
}
boolean isOk = Arrays.equals(arr, arr1);
if (isOk) {
System.out.println(" Pangram");
} else {
System.out.println("Not a pangram");
}
}
}
intha code la yen bro correct ans vara matrathu ?
bro in arr, u will store the duplicate characters, that means, if ur sttung has "cocon", two time c is stored
This is what i think
O(26)
Thats right!!!! 👏👏👏👍
But we conventionally use O(1) to denote constant space, as we ignore the coefficients when using Big O notation 😊😊
O(1)
Awesome na. 👏👏👏👏👏👏👍
Constant space thana...?
Yes na... Thats right
0(1)
That's right bro 👏👏👏👏👍
O(1)