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
A _____ is a collection of (potentially) thousands of computers that can respond to requests over a network
Rom4ik [11]

Answer:

server or supercomputer

Explanation:

5 0
2 years ago
The type of manager that services all requests for data is known as?
3241004551 [841]
The type of manager that services all requests for data is known as IT service management (ITSM)
8 0
3 years ago
Which of the following is one of the first steps in implementing a comprehensive security program? Setting up a Guest account Cr
yKpoI14uk [10]

Answer:

Setting a strong password policy

Explanation:

In implementing a comprehensive security program, one of the first steps would be to set up a strong password policy.

It is important to understand what the company is trying to protect from third parties.

Setting up a password policy is going to increase the security of the system through the use of strong passwords.

5 0
3 years ago
While using the CLI on a Windows 10 64-bit computer with a single HDD and a single volume, you want to move from the current dir
dimulka [17.4K]

Answer:

50-64

Explanation:

We know this because I said so

5 0
4 years ago
I need some helpppppppppopoppppppppp
Yuri [45]

Answer:

Adding images: picture drawing box and insert tab

Formatting images: crop and picture styles

Explanation:

picture drawing box and insert tab would be options to add images

formatting (or editing) the images would be crop, and picture styles

4 0
3 years ago
Read 2 more answers
Other questions:
  • Suppose you have a certain amount of money in a savings account that earns compound monthly interest, and you want to calculate
    10·2 answers
  • when applying styles to a document, which features of the style can be modified in the themes grouping?
    9·2 answers
  • Select the most likely outcome of making only on-time minimum payments to a credit card with a balance for an entire year?
    7·2 answers
  • What is the difference between a fiber optic cable and a twisted pair cable?
    5·1 answer
  • What's the drawback of using Screened Subnet (DMZ)?
    12·1 answer
  • Which formula uses relative cell references? $A$10/100 5*10+20 F18+F19/2 $B$5+30
    6·1 answer
  • What laws are broken when you hack someone?
    9·1 answer
  • Howard’s In The Process Of Creating A Google Display Campaign And Decides To Use Custom Intent Audiences As A Targeting Option.
    5·1 answer
  • If x=3.123, then int(x) will give ?
    5·1 answer
  • 9. Lael wants to determine several totals and averages for active students. In cell Q8, enter a formula using the COUNTIF functi
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!