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]);
}
}
}
}
}
My code shows correct solution of test 1 when I run it on my compiler. But, It gives wrong answer on test 1 when I submit it. Can anyone tell me the reason?
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, m, len;
cin>>n>>m;
int A[n], B[m];
for (int p = 0; p < n; p++){
cin>>A[p];
}
for (int q = 0; q < m; q++){
cin>>B[q];
}
int i = 0, j = 0;
while (i < n && j < m){
if (A[i] < B[j]){
cout<<A[i]<<" ";
i++;
}
else if (B[j] < A[i]){
cout<<B[j]<<" ";
j++;
}
else{
cout<<A[i]<<" ";
i++, j++;
}
}
/* Print remaining elements of the larger array */
while(i < n){
cout<<A[i]<<" ";
i++;
}
while(j < m){
cout<<B[j]<<" ";
j++;
}
return 0;
Could someone please tell me what’s wrong with this code?
N,M=map(int,input().split())
H=list(map(str,input().split()))
G=list(map(str,input().split()))
L=[]
for i in range(N):
L.append(H[i])
for i in range(M):
if G[i] not in L:
L.append(G[i])
U=sorted(L)
K=" ".join(U)
print(K)
a, b = map(int, input().strip().split())
c, d = input().strip().split(), input().strip().split()
c += d # join
c = list(dict.fromkeys(c)) # make unique
c.sort()
print(’ '.join(c))
I can’t understand why getting wrong answer?
Note: (c) is c in first bracket.
a = input()
c = input()
d = c.split()
d = set(d)
e = input()
f = e.split()
f = set(f)
g = d.union(f)
h = list(g)
h.sort()
j = ' '.join(map(str,h))
print(j)
It was accepted!
but if I validate the input, that was wrong in second test
x, y = map(int, input().split())
isValid=1
if 0<x<100 and 0<y<100:
a = {int(num) for num in input().split(" ", x)}
b = {int(num) for num in input().split(" ", y)}
a=list(a)
b=list(b)
for i in range(len(a)):
if i==0: continue
elif a[i-1]>a[i]:
isValid=0
break
for i in range(len(b)):
if i==0: continue
elif b[i-1]>b[i]:
isValid=0
break
a=set(a)
b=set(b)
result= a.union(b)
if isValid:
print(' '.join(str(s) for s in result))