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
A coworker is concerned about the veracity of a claim because the sender of an email denies sending it. The coworker wants a way
Aleks04 [339]

<u>Some recommend way to prove the authenticity of an email:</u>

  • The coworker as truthful to the company or organization he or she has to check where the same mail is sent long back to the same sender.
  • If search on emails sent item if he sends it will be well and good. Some time backup the mail will be help to proven authenticity of an email.
  • Sometimes once mail is downloaded into ms-outlook or lotus domino some time mail persists in the mail server.
  • He or she can coordinate with the mail server administrator to possible get a log file of sending mail and he can proceed as a record to management.
5 0
3 years ago
The act of illegally copying software, music,or movies that are copied protect?
miv72 [106K]
It’s protects piracy C
4 0
3 years ago
Read 2 more answers
Which bitwise operation has the same effect as multiplying a by 16?
Shalnov [3]
<span>Jun 15, 2011 - Multiplication and division can be achieved using bit operators, for example .... I discovered pretty much the same thing for Sun CC close to 20 years ago. ... Just to add a rough estimation: On a typical 16-Bit processor ..... Doing it yourself willaffect readability and possibly have no effect on performance.</span><span>
</span>
4 0
2 years ago
Read 2 more answers
Which framework can be used to develop cross-platform applications?
k0ka [10]

Answer:

Qt framework

Explanation:

3 0
3 years ago
Which of the following galaxy types is most likely to be clearly identifiable, regardless of orientation? SBc
Reil [10]

Answer:

The most likely galaxy type to be identifiable regardless of orientation is: Irr

Explanation:

The Irr galaxies don't have a discernable or usual shape; that is why it is relatively easy to identify.

When we talk about E type galaxies, this statement proves itself by the way the cumulus of stars compounds the galaxy. The elliptical galaxies have the form of ellipses, with a reasonable distribution of stars. The degree of eccentricity is the number that complements the E letter; that's why E0 galaxies are almost spherical, while E7 is considerably elongated.

SBc, SBa galaxies are spiral; this means it can be flat in some angles difficulting their identification process; in this case, the last letter means the way the arms display their form, with "c" having a vague form and "a" well-defined arms. That's why in some angles can be mistreated as another type of galaxy.

3 0
3 years ago
Other questions:
  • ___ is a career discipline focusing on helping companies use computer technology effectively.
    12·1 answer
  • Gunther is filling in his own input mask. He wants to format the Social Security numbers of his clients. The field must contain
    5·1 answer
  • (1) The given program outputs a fixed-height triangle using a * character. Modify the given program to output a right triangle t
    6·1 answer
  • Which of the following is NOT a component of a DFD?
    8·1 answer
  • Audio editing software contains several codecs that allow you to
    15·1 answer
  • Whats the size of a short bond paper in microsoft word?
    10·1 answer
  • A=1/2h(a+b) solve for h
    6·1 answer
  • Which of the following are NOT possible using the RANDOM(a, b) and DISPLAY(expression) abstractions?
    10·1 answer
  • What are your thoughts on copyright?<br><br> (Write 2 or more sentences)
    9·2 answers
  • Alice is watching a speech over the internet. what type of message is alice attending to?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!