1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kolbaska11 [484]
2 years ago
9

GoodArray hackerrank solution for a number N, a goodArray is the smallest possible array that consists of only powers of two

Computers and Technology
1 answer:
Paladinen [302]2 years ago
8 0

Using the knowledge in computational language in python it is possible to write a code that smallest possible array that consists of only powers of two.

<h3>Writting the code in python:</h3>

<em>"public class GoodArray {"</em>

<em />

<em> "public static List<Integer> getQueryResults(long N, List<List<Integer>> queries) {"</em>

<em />

<em>  "List<Integer> res = new ArrayList<>();"</em>

<em>  int[][] arr = new int[queries.size()][3];</em>

<em>  "List<Integer> goodArray = new ArrayList<>();"</em>

<em>  "for (int i = 1; i <= N; i++) {"</em>

<em>   "int num = i;"</em>

<em>   "while (num % 2 == 0) {"</em>

<em>    "goodArray.add(num);"</em>

<em>    "num = num / 2;"</em>

<em>   }</em>

<em>  }</em>

<em>  int index = 0;</em>

<em>  for (List<Integer> l : queries) {</em>

<em>   arr[index][0] = l.get(0);</em>

<em>   arr[index][1] = l.get(1);</em>

<em>   arr[index][2] = l.get(2);</em>

<em>   index++;</em>

<em>  }</em>

<em>  Collections.sort(goodArray);</em>

<em>  "for (int i = 0; i < arr.length; i++) {"</em>

<em>   "int[] query = arr[i];"</em>

<em>   int l = query[0];</em>

<em>   int r = query[1];</em>

<em>   int m = query[2];</em>

<em>   int prod = 1;</em>

<em>   "for (int j = l - 1; j <= r - 1; j++) {"</em>

<em>    "prod = (int) (prod * goodArray.get(j)) % m;"</em>

<em>   }</em>

<em>   res.add(prod);</em>

<em>  }</em>

<em>  return res;</em>

<em> }</em>

<em />

<em>}</em>

See more about python at brainly.com/question/18502436

#SPJ1

You might be interested in
Will Mark the brainliest
Sonbull [250]

Answer:

computer

Explanation:

By typing and answer and keep the data and have files

4 0
3 years ago
Which of the following statements is true of San serif fonts?
Vsevolod [243]
They are easier to read on a computer screen
7 0
3 years ago
Read 2 more answers
Using the intermediate COCOMO technique effort iscalculated in___________
Mashcka [7]

Answer: Four step process

Explanation:  COCOMO is a model for the estimation of the procedural software introduced by Barry Boehm. It is named as Constructive Cost Model and is referred as the process for prediction of the size,cost, quality and other such parameters. These parameters helps in making of the software more accurate and reliable. There are total of four step process for the calculation of intermediate COCOMO.

7 0
3 years ago
2 Name the package that contains scanner class?​
Marat540 [252]
the answer is Java.util.scanner
5 0
3 years ago
I need help with this
Mila [183]

Either Styles or Formula


5 0
3 years ago
Read 2 more answers
Other questions:
  • OSHA has authority over the employers of
    5·2 answers
  • Explain the purpose of the frame check sequence (fcs) field in a data link frame trailer.
    7·1 answer
  • What shortcut keys are used to go directly from global configuration mode to privileged exec mode?
    12·2 answers
  • What is another term used for data dictionary?
    12·1 answer
  • You have a network of ten computers connected to a single switch that has 12 ports. You need to add six more computers to the ne
    12·1 answer
  • Assume that the demand curve for DVD players shifts to the left and the supply curve for DVD players shifts to the right, but th
    6·1 answer
  • Look at (c), is it accurate? ​
    9·2 answers
  • What is coupling in computer science <br><br>​
    13·2 answers
  • What is draft pls help me​
    15·2 answers
  • Marc is creating a physical design, what aspect of the design deals with the interaction between a user and data?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!