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
The ______ is the information center that drivers need to refer to when they're NOT scanning the road.
Kruka [31]

Answer:

The  DIC (Driver Information Center)  is the information center

Explanation:

Scanning the road means that the road has to looked and analyzed for traffic jams, the cars that are coming close together and how fast the driver is driving etc, to keep ourselves safe from accidents.

If the driver is not scanning the road, then DIC will help the driver to find lots of useful information which keeps himself as well as the peer drivers on the road safe and thus avoiding accidents where by saving lives and heavy injury.

DIC will have Traffic details, navigation, entertainments, traffic signs, etc.

8 0
3 years ago
How can a search be narrowed to only search a particular website????
vesna_86 [32]

Answer:

There are a variety of ways to narrow down your search results in a library database. The two most direct ways are to focus your search with more specific keywords and/or to limit by various criteria before or after searching. The more specific you are with your search terms, the more relevant your results will be

Hope it helped!!!

4 0
3 years ago
Marissa bought 2 and 1/2 gallons of orange juice to make punch how many quarts of orange juice did Marissa Buy
Vladimir [108]
1 gallon = 4 quarts
using this information, you can then use simple proportion.
if 1 gallon = 4 quarts 
then to find the amount of quarts in 2 and 1/2 gallons, you multiply 2 and 1/2 by 4 which should give you 10 gallons
5 0
3 years ago
Read 2 more answers
A technician is using a network-attached desktop computer with a Type 2 hypervisor to run two VMs. One of the VMs is infected wi
lianna [129]

Answer:

Place both VMs on virtual NICs that are isolated from the company LAN.

Explanation:

From the scenario above, for the technician to best protect the company's LAN while performing the above mentioned tests, it us best to place both VMs on virtual NICs that are isolated from the company LAN.

Cheers

4 0
4 years ago
A type of storage which holds data on a permanent basis for later use<br><br><br><br> Help please
nikdorinn [45]

Answer:

Permanent storage, also called persistent storage, is any computer data storage device that retains its data when the device is unpowered. A common example of permanent storage is the computer's hard drive or SSD.

Explanation:

4 0
3 years ago
Other questions:
  • The statements that a programmer writes in a high-level language are called ________.
    9·2 answers
  • Help me Please?!! I will put you as brainliest.<br>I hope I spelled that right.
    5·2 answers
  • Let’s say you’re publishing a message with the Hootsuite Composer. The message contains a link to a landing page, and you want t
    9·1 answer
  • What command displays a computer s network settings?
    5·1 answer
  • The length property of the String object returns
    15·1 answer
  • An HTML document is composed of ______ that represent distinct items in the Web Page, such as a paragraph, the page heading, or
    9·1 answer
  • Suppose a family has had a house fire in which
    7·2 answers
  • B. What significant values have you learned while learning the tools and utensils?
    8·1 answer
  • Frank enters "1" in the field for postal code. What is frank most likely trying to do?
    13·2 answers
  • Pls say correct guyz pls pls pls
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!