for second question we can simply use hashet where all the letters of first text should be added and then next we need to check we each letter of rahul is there in it or not if !ocntains dirreclty return 1 after loop return 0
in the second question what if we convert it into character array and sum the ascii value of the words, if same then copied not same means not copied. Will it work?
// Online Java Compiler // Use this editor to write, compile and run your Java code online BRUTEFORCE import java.util.Arrays; class Main { public static void main(String[] args) { int marks = 0; String adjacentStudentWord = "HELLO"; String RahulWord = "EHLLO"; char arr[] = adjacentStudentWord.toCharArray(); char arr2[] = RahulWord.toCharArray(); Arrays.sort(arr); Arrays.sort(arr2); if(Arrays.equals(arr,arr2)){ marks = 1; } System.out.println(marks);
Can't we just compare the characters of both the string in single loop and if the characters on the same level don't match just stop the loop and return
✅✅Join Our Telegram Group for Infosys 2025 Batch Discussion : t.me/placement_batch_2025
for second question we can simply use hashet where all the letters of first text should be added and then next we need to check we each letter of rahul is there in it or not if !ocntains dirreclty return 1 after loop return 0
in the second question what if we convert it into character array and sum the ascii value of the words, if same then copied not same means not copied. Will it work?
no
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
BRUTEFORCE
import java.util.Arrays;
class Main {
public static void main(String[] args) {
int marks = 0;
String adjacentStudentWord = "HELLO";
String RahulWord = "EHLLO";
char arr[] = adjacentStudentWord.toCharArray();
char arr2[] = RahulWord.toCharArray();
Arrays.sort(arr);
Arrays.sort(arr2);
if(Arrays.equals(arr,arr2)){
marks = 1;
}
System.out.println(marks);
}
}
Can't we just compare the characters of both the string in single loop and if the characters on the same level don't match just stop the loop and return
import java.util.*;
class Main {
public static void main(String[] args) {
boolean ans=true;
String s="AVINASH";
String v="HSANIVA";
HashMap hm=new HashMap();
for(int i=0;i
I did.