Find Password 1 – Wipro Sample Coding Question Solved – codewindow.in

Detective Buckshee Junior has been approached by the Shantiniketan kids society for help in finding the password to the game’s complex. After hearing the scenario, detective Buckshee junior realizes that he will need a programmer’s support. He contacts you and requests your help. Please help the detective by writing a function to generate the password.
The scenario is as below:
Five numbers are available with the kids.
These numbers are either stable or unstable.
A number is stable if each of its digits occurs the same number of times, i.e. the frequency of each digit in the number is the same.For e.g. 2277, 4004, 11, 23, 583835, 1010 are examples of stable numbers.
Similarly, A number is unstable if the frequency of each digit in the number is NOT the same. For e.g. 221, 4314, 101, 233, 58135, 101 are examples of unstable numbers.
The password can be found below:
i.e. Password = Maximum of all stable numbers + Minimum of all Unstable numbers.
Assuming that the five numbers are passed to a function as input1, input2, input3, input4, and input5, Complete the function to find and return the password.
For Example:
if input1 = 12, input2 = 1313, input3 = 122,input4 = 678, input5 = 898, stable numbers are 12, 1313 and 678
Unstable numbers are 122 and 898.
So, the password should be = Maximum of all stable numbers + Minimum of all Unstable numbers = 1313 + 122 = 1435

Cognizant Solutions | CodeGladiators Solutions​

Solution

import java.io.*;
import java.util.*;

class CodeWindow {
  public int findPassword(int input1, int input2, int input3, int input4, int input5) {
    ArrayList<Integer> arrStable = new ArrayList<Integer>(5);
    ArrayList<Integer> arrUnstable = new ArrayList<Integer>(5);

    if (stable_no(input1))
      arrStable.add(input1);
    else
      arrUnstable.add(input1);

    if (stable_no(input2))
      arrStable.add(input2);
    else
      arrUnstable.add(input2);

    if (stable_no(input3))
      arrStable.add(input3);
    else
      arrUnstable.add(input3);

    if (stable_no(input4))
      arrStable.add(input4);
    else
      arrUnstable.add(input4);

    if (stable_no(input5))
      arrStable.add(input5);
    else
      arrUnstable.add(input5);

    return Collections.max(arrStable) + Collections.min(arrUnstable);
  }

  static void frequency(int number, int[] result) {
    int temp = 0;
    while (number != 0) {
      temp = number % 10;
      if (temp < 0) {
        temp = -temp;
      }
      result[temp]++;
      number /= 10;
    }
  }

  static boolean stable_no(int number) {
    int[] result = new int[10];
    for (int i = 0; i < 10; ++i) {
      result[i] = 0;
    }
    int auxiliary = 0, status = 1;
    frequency(number, result);
    for (int i = 0; i < 10 && status == 1; ++i) {
      if (result[i] != 0) {
        if (auxiliary == 0) {
          auxiliary = result[i];
        } else if (auxiliary != result[i]) {
          status = 0;
        }
      }
    }
    if (status == 0) {
      return false;
    } else {
      return true;
    }
  }
}

Coding Questions

  1. Coding Question

    Write a complete C program to convert a given temperature in Centigrade scale to its equivalent Fahrenheit scale.

  2. Coding Question :

    Write a function to swap the value of 2 variables without using any additional variable. The change should be permanent.

  3. Coding Question :

    Write a program to check a number whether it is odd or even by the bitwise operator.

  4. Coding Question :

    Write a C program to print the following pattern(till n rows, where n is taken as input).

            1
          0  1
        0 1  0
     1  0  1  0
    1 0 1  0  1

  5. Coding Question :

    Write a C program to accept three integer numbers as the length of three sides of a triangle, test the validity of lengths, and classify the triangle.

  6. Coding Question :

    Write a program to generates all combinations of 1,2 and 3 using for loop.

  7. Coding Question :

    Write a program in C to find the roots of a quadratic equation. Your program should print the imaginary roots in the form a+ib.

  8. Coding Question :

    Write a program to print a Pattern.               

    1
    0 1
    1 0 1
    0 1 0 1
    1 0 1 0 1

  9. Coding Question :

    Write a program to find the sum of the digits of a number.

  10. Coding Question :

    Write a program to check a number is palindrome or not. 

  11. Coding Question :

    Write a C program to print the Pattern.

              1
           1 0  1
        1 0 1 0 1  
     1 0 1 0 1 0 1

  12. Coding Question :

    Write a program to accept a number and find the sum of its individual digits repeatedly till the result is a single digit.

  13. Coding Question :

    Write a program to compute 

    e= 1+ 1/1! + 1/2! + 1/3! ….1/n! with accuracy of 0.001%.

  14. Coding Question :

    Write a program to print the sum of three digits prime numbers.

  15. Coding Question :

    Write a C program to check a number is prime or not.

  16. Coding Question :

    Write a program to print the  following pattern (Number of lines should be given as input by the users).

  17. Coding Question :

    Write a C program to check a number is prime or not.

  18. Coding Question :

    Write a program which take an integer as input and print the digits of an integer in words, after storing in a character array. [ if input : 2403 , output : Two Four Zero Three]

  19. Coding Question :

    Write a C program to count the frequency of each vowel from a user-supplied string.

  20. Coding Question :

    The equation x2+y2=r2 represent a circle which centers at origin and radius is r. Write a program that read r from the keyboard and print the number of points with integer co-ordinate that lie on the circumference of the circle.   

  21. Coding Question :

    Write a program to print Pascal’s triangle.

  22. Coding Question :

    Write a program to display the prime factors of an integer.(The number is input).

  23. Coding Question :

    Write a program which will print the following pattern(no of the line is input).

  24. Coding Question :

    Write a C program to print the prime numbers between 1 to 100.

  25. Coding Question :

    Write a C program that will search the kth element in a list of n integers.

  26. Coding Question :

    Write C program to solve: xsin(x)

  27. Coding Question :

    Write C programs to solve : x3=249

  28. Write a program to find the value of sin(x) , x=0,15,30,…,345,360 with an accuracy of 10-4 avoiding use of abs function.

  29. Coding Question :

    Write a program to convert decimal numbers in the range 1 to 9999 in to Roman numerals where , I=1,V=5, X=10, L=50,C=100,D=500,M=1000 and assuming L=5000.

  30. Coding Question :

    Write a C program to find Greatest Common Divisor(GCD) for n number.

  31. Coding Question :

    Write a  recursive function to print the content of an array on reverse order, Write the main() function to call that recursive function. 

  32. Coding Question :

    Write a program to print Fibonacci series using recursive.

  33. Coding Question :

    Write a c-program to convert binary number to equivalent decimal number.

  34. Coding Question :

    Write a program to check a number is special or not. (Special is a number which is  equal to the sum of factorial of each digit of the given number).

  35. Coding Question :

    Write a C-program to implement the Tower of Hanoi problem using recursion.

  36. Coding Question :

    Write two C programs that calculates factorial of a number using recursion and iteration.

  37. Coding Question :

    Write a function to sort the characters of the string passed to it as argument.

  38. Coding Question :

    Write a program in C which prints the smallest divisor of an integer , for example smallest divisor of 77 is 7.

  39. Coding Question :

    Write a C program to find the average of n numbers.

  40. Coding Question :

    Write a program to create an array of n elements and then print maximum and minimum elements from that array.

  41. Coding Question :

    Write a C program which will take input in a 2D array and then take one integer as input and search it is available or not, if it is available display the row and column of the integer.

  42. Coding Question :

    Write a program to find the transpose of a matrix.

  43. Coding Question :

    Write a program to insert an element (given by the user) into an array in a particular position(given by the user).

  44. Coding Question :

     Write a recursive C program to multiply two 3×3 matrices.

  45. Coding Question :

    Write a C-program to implement binary searching.