Java sort 4 arrays into 1 array

Step 1: Combine all the arrays Step 2: Sort arrays using Arrays.sort(array); Step 3: Remove the duplicates. int[] a = {1,2,3,4,5}; int[] b = {1,2,3,4,5,6}; int[] c = {1,3,7}; int[] d = {2,3,4,8,9,10}; int[] resultArray1 = new int[a.length+b.length+c.length+d.length]; int arrayIndex = 0; for (int i=0; i< a.length ; i++, arrayIndex++ ) { resultArray1[arrayIndex] = a[i]; … Read more

What is wrong with the following code which calculates a sorted array [closed]

int size=sizeof(sequence); You probably meant int size=sequence.size(); which actually returns the number of elements in the std::vector container. vector <int> s1; for(i=0;i<size;i++) { s1[i]=stoi(sequence[i]); } Here the problem is that the vector s1 is initialized as empty, so that you cannot change the i-th value (because it does not exist). Give the std::vector directly the … Read more

Assorting linked list in c [duplicate]

Simplest will be bubble sort. item* sort(item *start){ item *node1,*node2; int temp; for(node1 = start; node1!=NULL;node1=node1->next){ for(node2 = start; node2!=NULL;node2=node2->next){ if(node2->draw_number > node1->draw_number){ temp = node1->draw_number; node1->draw_number = node2->draw_number; node2->draw_number = temp; } } } return start; }

How to approach this hackerrank puzzle?

I could not post it to comment section. Please see below: List<Integer> integers = Arrays.asList(1, 2, 3, 4); int i = 0; StringBuilder sb = new StringBuilder(“[“); for (int value : integers) { sb.append((i == 0) ? “” : (i % 2 == 0 ? “,” : “:”)).append(value); i++; } sb.append(“]”); System.out.println(sb.toString()); Output is: [1:2,3:4]

How to get popular keywords in an array

array_count_values will output the count as like Array ( [keyword1] => 10 [keyword2] => 3 [keyword3] => 6 [keyword4] => 5 [keyword5] => 1 ) But For your desired output you need to use foreach Demo $arra = Array ( 0 => “keyword1”, 1 => “keyword1”, 2 => “keyword1”, 3 => “keyword1”, 4 => “keyword1”, … Read more