Oh! Sorry! @Abdullah_1234 I didn’t specifically meant the last loop.
I wanted to mean drop the if statement in the last loop.
And also sort the list y before that.
Miscalculations from both side I think.
y is guaranteed to be sorted already but what @Abdullah_1234 is doing is appending new elements of x in its end.
So, he requires to sort it again.
I tested it before commenting.
Are you sure, bhaia? Because, these tree lines of code:
for i in x:
if i not in y:
y.append(i)
Is doing the following:
Take each element from X
If it satisfies a condition, append it to the back of Y:
Now, if X is originally sorted, then Y will be sorted at the end for sure.
Let’s take this list for example:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
If you take each element from here from left to right, and push the odd ones to a new list, the new list will have the odd numbers in sorted order. Shouldn’t it?
Oh! Sorry, my bad. submission
I didn’t notice that he took an empty list for calculations.
Hmm, It will work even without sorting.
Btw, @hjr265 bro, It is a long time since I have argued over codes.
Hope to argue with you again.
Can you help me with a problem of mine after the end of the mock contest?
Thanks bro.
I was absent for quite a few days because I had to study to complete my syllabus for the upcoming exam.
Hope you will also help in the future
can u please find problem in this one? It is just passing sample case
a,b=input().split()
c=input()
d=input()
if len(c)==2*int(a)-1 and len(d)==2*int(b)-1:
e=set(c)
f=set(d)
g=(e|f)
h=list(g)
h.sort()
h.remove(" ")
string=""
for element in h:
string=string+element
string=string+" "
i=list(string)
i.pop()
str1=""
for elements in i:
str1=str1+elements
print(str1)
import java.util.Arrays;
import java.util.Scanner;
class Main_practice{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
sc.nextLine();
String l1 = sc.nextLine();
String l2 = sc.nextLine();
String array1 [] = l1.split(" ");
String array2 [] = l2.split(" ");
String sa [] = new String [array1.length+array2.length];// new array having length of (array1.length + array2.length)
for(int i = 0;i<array1.length;i++){ // taking all the values of array1 in sa array
sa[j++] = array1[i];
}
for(int i=0;i<array2.length;i++){ //// taking all the values of array2 in sa array
sa[j++] = array2[i];
}
Arrays.sort(sa);// sorting the sa array in in increasing order.
for(int i=1;i<sa.length;i++){// iterating the sa array from 1 index, as i will be checking the previous value in the array is same with sa[i] or not. if not same then i will print the sa[i-1]
if(i<sa.length-1){// checking this if it is the index before the last index of sa array,if so then i will print based on the condition in the same line with a space
if(!sa[i].equals(sa[i-1])){ // star
System.out.print(sa[i-1]+" ");
}
}
else{
if(!sa[i].equals(sa[i-1])){// if last index and its previous index's value is not same, then i will print sa[i] and sa[i-1] both else the a[i-1] index's value
System.out.println(sa[i-1]+" "+sa[i]);
}
else{
System.out.println(sa[i-1]);
}
}
}
}
}[quote="emo_19301245, post:52, topic:1690, full:true"]
import java.util.Arrays;
import java.util.Scanner;
class Main_practice{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
sc.nextLine();
String l1 = sc.nextLine();
String l2 = sc.nextLine();
String array1 [] = l1.split(" ");
String array2 [] = l2.split(" ");
String sa [] = new String [array1.length+array2.length];// new array having length of (array1.length + array2.length)
for(int i = 0;i<array1.length;i++){ // taking all the values of array1 in sa array
sa[j++] = array1[i];
}
for(int i=0;i<array2.length;i++){ //// taking all the values of array2 in sa array
sa[j++] = array2[i];
}
Arrays.sort(sa);// sorting the sa array in in increasing order.
for(int i=1;i<sa.length;i++){// iterating the sa array from 1 index, as i will be checking the previous value in the array is same with sa[i] or not. if not same then i will print the sa[i-1]
if(i<sa.length-1){// checking this if it is the index before the last index of sa array,if so then i will print based on the condition in the same line with a space
if(!sa[i].equals(sa[i-1])){ // star
System.out.print(sa[i-1]+" ");
}
}
else{
if(!sa[i].equals(sa[i-1])){// if last index and its previous index's value is not same, then i will print sa[i] and sa[i-1] both else the a[i-1] index's value
System.out.println(sa[i-1]+" "+sa[i]);
}
else{
System.out.println(sa[i-1]);
}
}
}
}
}