import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner input = new Scanner (System.in); int Q = input.nextInt (); //Store answer to each query StringBuilder output = new StringBuilder(""); queries:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Can you explain this code? It is "Permuting Two Arrays" Hackerrank question's solution.

31
import java.io.*;
32
import java.util.*;
33
34
public class Solution {
35
36
public static void main(String[] args) {
37
Scanner input = new Scanner(System.in);
int Q = input.nextInt();
38
%3D
39
//Store answer to each query
40
StringBuilder output
= new StringBuilder("");
41
42
queries:
for (int q =
0; q < Q; q++)
43
44
{
45
int n =
input.nextInt();
int k - input.nextInt();
46
47
48
//Initialize Input
int[] A = new int[n];
49
50
int[] B= new int[n];
for (int i = 0; i < n; i++)
51
52
A[i]
input.nextInt();
for (int i = 0; i < n; i++)
53
54
B[i] = input.nextInt();
55
56
Arrays.sort(A);//Sort ascending
57
Arrays.sort(B);//Sort acending
58
for (int i = 0; i < n; i++)
59
60
{
Transcribed Image Text:31 import java.io.*; 32 import java.util.*; 33 34 public class Solution { 35 36 public static void main(String[] args) { 37 Scanner input = new Scanner(System.in); int Q = input.nextInt(); 38 %3D 39 //Store answer to each query 40 StringBuilder output = new StringBuilder(""); 41 42 queries: for (int q = 0; q < Q; q++) 43 44 { 45 int n = input.nextInt(); int k - input.nextInt(); 46 47 48 //Initialize Input int[] A = new int[n]; 49 50 int[] B= new int[n]; for (int i = 0; i < n; i++) 51 52 A[i] input.nextInt(); for (int i = 0; i < n; i++) 53 54 B[i] = input.nextInt(); 55 56 Arrays.sort(A);//Sort ascending 57 Arrays.sort(B);//Sort acending 58 for (int i = 0; i < n; i++) 59 60 {
61
//Traverse A ascending and B descending
62
if(A[i]+B[B.length-1-i] < k) //Failed check
63
{
64
output.append("NO\n");
65
continue queries;
66
}
67
}
68
69
//Permutation exist
70
output.append("YES\n");
71
72
73
//Print the answers to all queries
74
System.out.println(output);
75
}
76
}
Transcribed Image Text:61 //Traverse A ascending and B descending 62 if(A[i]+B[B.length-1-i] < k) //Failed check 63 { 64 output.append("NO\n"); 65 continue queries; 66 } 67 } 68 69 //Permutation exist 70 output.append("YES\n"); 71 72 73 //Print the answers to all queries 74 System.out.println(output); 75 } 76 }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education

Expert Answers to Latest Homework Questions

Q: None
Q: Crane Decor sells home decor items through three distribution channels-retail stores, the Internet,…
Q: Question 9 Name the following structure: CH3CH2 C CH2CH3
Q: Wildhorse Inc. had these transactions pertaining to investments in common stock: Jan. 1 July 1…
Q: Microbial growth rate in an aeration tank is governed by Arrhenius relationship. If the growth rate…
Q: Identify the product of this reaction. Д A B C D
Q: Math 206 7. (10 points) Let X be a random variable with standard normal distribution, i.e., X ~…
Q: Using the following plot of data about a population, determine the greatest rate of change of…
Q: S Wescott Company has three divisions: A, B, and C. The company has a hurdle rate of 8 percent.…
Q: what is the molecular fomula for this please
Q: Draw the monomer(s) used to make the following polymers (end-groups have not been included). If more…
Q: Unpolarized light passes through two Polaroid sheets. The transmission axis of the analyzer makes an…
Q: Question 9 (3 points) Name the following: HO H₂N
Q: Suppose that a comet that was seen in 502 A.D. by Chinese astronomers was spotted again in year…
Q: dont given AI solution...
Q: given full reaction with explanin and dont given AI solution ....
Q: Walton Company has measured its quality costs for the past two years. After the company gathers its…
Q: Click the "draw structure" button to launch the drawing utility. Draw the organic products formed in…
Q: What is (are) the product(s) in the reaction below? Mark all that apply. Br N-Br H₂O2 Br Br Br A B C…
Q: Needed help
Q: The maximum deflection for the cantilever-beam below is no more than 0.03m.Macaulay’s method of…