+ 1
Can you take 1 minute to help me ??
https://code.sololearn.com/c8u1x016La68/?ref=app I know the logic to print size. however, I want to print those 4 elements which are common in two arrays ???
7 Answers
+ 2
for(int i : b) {
if(set.contains(i)){
count++;
set.remove(i);
System.out.print(i + " ");
}
}
System.out.println("\n" + count);
+ 3
User42 now i corrected it , big O of n square.
I think you are a beginner. let me tell you about this.
Time complexity is the time taken by an algorithm as a function of inputs of length. You will read about it in data structure and algorithms.
+ 2
User42 time complexity of your given solution is O(n^2) ?? Am i right ??
+ 1
User42 yes you are right if we need to print intersecting elements.I think (remove) should be included when you need to return Size of intersecting elements because it won't allow the same numbers to be counted twice.
0
Davinder Kumar
HashSet<Integer> set = new HashSet<>();
for(int i : a) {
for (int j : b) {
if (j == i) {
//set.add(j);
System.out.print(i + " ");
count++;
}
}
}
System.out.println("\n" + count);
0
#include<stdio.h>
int main(void)
{
int num1,num2;
printf("enter two numbers");
scanf("%d%d",&num1,&num2);
if(num1>number2){
printf("greater number is %d", number1);
}else{
printf("greater number is %d", number2);
}
return 0;
}
what is the error on this?