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
Mrac [35]
2 years ago
8

Given an array of integers a, your task is to calculate the digits that occur the most number of times in the array. Return the

array of these digits in ascending order.
Computers and Technology
1 answer:
Annette [7]2 years ago
3 0

Answer:

I hope this should be helpful

Explanation:

In Javascript

function solution(numbers) {

   let hashmap = {};

   let ans = [];

   for (let i = 0; i < numbers.length; i++) {

     // check wether it double or single digit

     if (hasOneDigit(numbers[i])) {

       // check if it exists in hashmap

       // if exist add number of occurence

       // check if the occurence is greater than 2

       // add  if > 2 to the answer list

       if (numbers[i] in hashmap) {

         hashmap[numbers[i]] = hashmap[numbers[i]] + 1;

 

         if (hashmap[numbers[i]] = 2 && !ans.includes(numbers[i])) {

           // max_freq = hashmap[numbers[i]]

           ans.push(numbers[i]);

         }

         // else if (max_freq == hashmap[numbers[i]])

         //     ans = min(ans, numbers[i])

       } else {

         hashmap[numbers[i]] = 1;

       }

     } else {

       // change number to string

       number = numbers[i].toString();

       // loop to iterate every single element

       for (let j = 0; j < number.length; j += 1) {

 

         if (+number.charAt(j) in hashmap) {

           hashmap[+number.charAt(j)] = hashmap[+number.charAt(j)] + 1;

 

           if (hashmap[+number.charAt(j)] = 2 && !ans.includes(+number.charAt(j))) {

     

             ans.push(+number.charAt(j));

           }

       

         } else {

             hashmap[+number.charAt(j)] = 1

         }

       }

     }

   }

     return ans.sort();

 }

 

 function hasOneDigit(val) {

   return String(Math.abs(val)).charAt(0) == val;

 }

 console.log(solution([2, 1,42,44, 2, 3,32,7777, 3 , -1]));

 

You might be interested in
The fast food restaurant Chipotle pulled its app from Apple's app store when customer demand caused the firm's servers to crash.
Ad libitum [116K]

Answer:

A. AWS

Explanation:

Amazon Web Services AWS -

It is one of the subsidiary of the Amazon , which enables various functions like , API's , on - demand cloud computing platform , on the metered pay - as - you - go basis .

It helps to have a virtual computing services at any time and helps to provide all the services a real computer can offer , with the similar efficiency .

One of the service is the Amazon Elastic Compute Cloud .

The technology is very convenient and efficient in its service and hence is used by various people , in companies , restaurants etc.

Hence , from the given scenario of the question ,

The correct answer is A. Amazon Web Services AWS .

8 0
3 years ago
Meaning of page break​
zmey [24]

Answer:

a point at which a price of continuous text is split into two pages

Explanation:

for ex: a page break is treated as a single character in the document.

6 0
3 years ago
What does the hard disk drive do? It stores all of the information on a computer. It controls a computer’s operating system. It
umka21 [38]

The hard disk drive, OR HDD Stores all the information on the computer.

5 0
4 years ago
Read 2 more answers
Explain the look of a document which contains several different font sizes and font colors​
Firlakuza [10]

Answer:

Colorful and dynamic?

Explanation:

8 0
3 years ago
Consider the following sequence, defined from n=2 to 15 (inclusive). Pn=n2−1. Produce a list named primes which only contains va
omeli [17]

Answer:

primes = []

for n in range(2,16):

   pn = n*n - 1

   if is_prime(pn):

       primes.append(pn)

5 0
3 years ago
Other questions:
  • The computer mouse is used to
    11·1 answer
  • While designing your network's VLAN topology, your team has decided to use a centrally managed DHCP server rather than creating
    8·1 answer
  • Online Book Merchants offers premium customers 1 free book with every purchase of 5 or more books and offers 2 free books with e
    11·1 answer
  • Two of the major sources used today for obtaining information to create computer maps are satellites and _____________.
    11·2 answers
  • Controlling access of information on the internet
    15·1 answer
  • 7.5 Code practice Plz answer ASAP
    15·1 answer
  • You are responsible for a rail convoy of goods consisting of several boxcars. You start the train and after a few minutes you re
    8·1 answer
  • Question is on the picture thank you
    10·1 answer
  • When a derived class method has the same name as a base class method, it is often said that the derived class method ________ th
    13·1 answer
  • Which of the following is typiacally the last step of the mail merge process
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!