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]
1 year 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]1 year 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
How we can earn from an app​
miss Akunina [59]

Answer:

Hewo, Here are some ways in which apps earn money :-

  • Advertisement
  • Subscriptions
  • In-App purchases
  • Merchandise
  • Physical purchases
  • Sponsorship

hope it helps!

5 0
2 years ago
The set of three integer values for the lengths of the sides of a right triangle is called a Pythagorean triple. These three sid
Sloan [31]

Answer:

In Python:

def  Pythagorean_triple(hyp,side1,side2):

   if hyp**2 == side1**2 + side2*2:

       return True

   else:

       return False

               

print("Hypotenuse\tSide 1\t Side 2\t Return Value")

for i in range(1,501):

   for j in range(1,501):

       for k in range(1,501):

           print(str(i)+"\t"+str(j)+"\t"+str(k)+"\t"+str(Pythagorean_triple(i,j,k)))

Explanation:

This defines the function

def  Pythagorean_triple(hyp,side1,side2):

This checks for pythagorean triple

   if hyp**2 == side1**2 + side2*2:

Returns True, if true

       return True

   else:

Returns False, if otherwise

       return False

               

The main method begins

This prints the header

print("Hypotenuse\tSide 1\t Side 2\t Return Value")

The following is a triple-nested loop [Each of the loop is from 1 to 500]

for i in range(1,501): -->The hypotenuse

   for j in range(1,501): -->Side 1

       for k in range(1,501):-->Side 2

This calls the function and prints the required output i.e. the sides of the triangle and True or False

           print(str(i)+"\t"+str(j)+"\t"+str(k)+"\t"+str(Pythagorean_triple(i,j,k)))

8 0
2 years ago
I WILL GIVE BRAINLIST THING TO WHOEVER GIVES ME THE CORRECT ANSWER
Anna11 [10]

Answer:

Evaluate and compare free and commercial versions of the antivirus software provided at the link above. Based on the information you learned in this Unit, what differences, if any, are significant enough to warrant considering paying for the software versus using the free version (for a typical home user, if the specific annual costs were not a major consideration)? What is “missing” from the personal/home/base level subscription that you might want?

Explanation:

4 0
2 years ago
Using a personal computer to produce high quality printed documents
alisha [4.7K]

Answer:

Desktop publishing

6 0
3 years ago
List the steps that you need to locate Microsoft Word on your computer
Olegator [25]
1.click windows start button on the bottom left corner
2. search Microsoft word
3.once Microsoft word is found right click on it
4. then you will see an option called "open file location"
5. then you will have the location of microsoft word
6 0
3 years ago
Other questions:
  • One main advantage of CD-ROMs is that..
    7·1 answer
  • Driving while wearing headphones or earphones
    12·2 answers
  • For the following array x [10] = { 45, 20, 50, 30, 80, 10, 60, 70, 40, 90} show the contents of x after the function call split
    6·1 answer
  • Anna is looking for a job. Which two types of skills would she find necessary to secure a job ?
    5·1 answer
  • Match each type of software license with the appropriate definition.
    11·1 answer
  • When you use information hiding by selecting which properties and methods of a class to make public, you are assured that your d
    14·1 answer
  • Se numeşte permutare a unei mulţimi finite orice rearanjare a tuturor elementelor acelei mulţimi.
    14·1 answer
  • Edhesive assignment 1 movie ratings
    9·1 answer
  • HELP FAST PLS<br> Do you care more about avoiding fees/costs, accumulating perks, convenience, etc?
    14·2 answers
  • How do I add a Child to my Brainly account
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!