Posts

Average of all elements

 Question:--   Find the counts of elements of an unsorted integer array which are equal to the average of all elements of that array. Ex: Input Case 1:     input: [2,2,2,2,2]  output:  5 solution : 2+ 2+ 2+ 2+ 2 = 10/5 ==> 2 it contain five 2 element Input Case 2:     input: [ 1,3,2,4,5]    output:  1 solution : 1+ 3+ 2+ 4+ 5 = 15/5 ==> 3 it contain one 3 element       JavaScript Solution:--- function avg(a,n){     var num = []     var sum = 0     for (i=0; i < n; i++){        sum+=a[i]     }     // console.log(sum)     // console.log(sum/n)     // console.log(sum/n)     //  return sum              for (var i of a){         if (i == sum/n){      ...

call Back Hell, Promise, Async Await

Remember To solve call back hell:---- We use Promise Async and Await enhances Promise

C++ BASICS

 #include <iostream> #include <string> using namespace std; // f(x) = x^2 + 2 int add(int a, int b) {     int c;     c = a + b;     return c; } class Employee { public:     string name;     int salary;     Employee(string n, int s, int sp)     {         this->name = n;         this->salary = s;         this->secretPassword = sp;     }     void printDetails()     {         cout << "The name of our first employee is " << this->name << " and his salary is " << this->salary << " Dollars" << endl;     }     void getSecretPassword()     {         cout<<"The secret password of employee is "<<this->secretPassword;     } private:     int secretPassword; }; class Progra...

JAVA Basics

 package com.codewithharry; import java.util.Scanner; public class Main {     static int sum(int a, int b){         return a+b;     }     public static void main(String[] args) { // Write your code here //        System.out.println("Hello World");      /* Variables      Just Like:         -Water - Bucket         -Masala - box         -Lunch - LunchBox      In Java:      Variables are containers which store data values      String, int, float, char, boolean      How to declare variables:      syntax - <dataType> <variableName> = <value>;       */      String name = "Harry";      String channel = "CodeWithHarry"; //     System.out.println(name); //     System...

C Basics

1:--  #include <stdio.h> int main(){     printf("Hello World\n");     return 0; }   2:-- #include <stdio.h> int main() {     // Single line comments: compiler will ignore this     /*     this is a multi     line      comment     */     // int, float, char     int a1 = 7;                 // 2 to 4 bytes     unsigned short integer = 8; // 2 bytes     long integer1 = 8;          // 4 bytes     short integer2 = 8;         // 2 bytes     float b1 = 8.0;                    // 4 bytes - 6 decimal precision     double myfloat1 = 7.45;            // 8 bytes - 15 decimal places precision     long double myfloat2 = 7.43453455; // 10 bytes - 1...

Company Logo | HackerRank Solutions

  A newly opened multinational brand has decided to base their company logo on the three most common characters in the company name. They are now trying out various combinations of company names and logos based on this condition. Given a string   , which is the company name in lowercase letters, your task is to find the top three most common characters in the string. Print the three most common characters along with their occurrence count. Sort in descending order of occurrence count. If the occurrence count is the same, sort the characters in alphabetical order. For example, according to the conditions described above,  would have it's logo with the letters  . Input Format A single line of input containing the string  . Constraints  has at least   distinct characters Output Format Print the three most common characters along with their occurrence count each on a separate line. Sort output in descending order of occurrence count. If the occurrence...