+ 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 ???

3rd Jul 2022, 7:09 AM
Davinder Kumar
Davinder Kumar - avatar
7 Answers
+ 2
for(int i : b) { if(set.contains(i)){ count++; set.remove(i); System.out.print(i + " "); } } System.out.println("\n" + count);
3rd Jul 2022, 8:23 AM
AĶ¢J
AĶ¢J - avatar
+ 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.
3rd Jul 2022, 9:02 AM
Davinder Kumar
Davinder Kumar - avatar
+ 2
User42 AĶ¢J Thanks you
3rd Jul 2022, 8:26 AM
Davinder Kumar
Davinder Kumar - avatar
+ 2
User42 time complexity of your given solution is O(n^2) ?? Am i right ??
3rd Jul 2022, 8:38 AM
Davinder Kumar
Davinder Kumar - avatar
+ 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.
3rd Jul 2022, 8:33 AM
Davinder Kumar
Davinder Kumar - avatar
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);
3rd Jul 2022, 8:35 AM
AĶ¢J
AĶ¢J - avatar
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?
4th Jul 2022, 5:10 PM
Nadhil An
Nadhil An - avatar