Deloitte Off Campus 2022 Coding Question

Deloitte off Campus 2022 Coding Question and Solution

In this post we will see Deloitte off campus 2022 coding problem with step by step solution and complete code in java.

Question:

Write a program to analyse the characters in the string str and find N which is the number of occurrence of the highest ASCII value. Then print the character having lowest ASCII  value in str, N times. The string str can contain special characters or alphanumeric or mix of all. The string can represent in any case. Read the input from keyboard and return the output

 Constraints: Length of str>0

Input:

The input will be string to be analysed

Output: The output contains lowest ASCII equivalent character value printed N times

Sample input1:

ABOVEtheheight

Sampleoutput1:

A

A

Explanation :

ASCII value of A =65

ASCII value of B =66

ASCII value of O =79

ASCII value of V =86

ASCII value of E =69

ASCII value of t =116

ASCII value of h =104

ASCII value of e =101

ASCII value of h =104

ASCII value of e=101

ASCII value of i =105

ASCII value of g =103

ASCII value of h =104

ASCII value of t =116

Algorithm

  1. Let us take “DATTA” as an input string , so first step is already done we have read input from keyboard
  2. Further convert “DATTA” string to array format, as it will be easy to iterate through array elements.
  3. Here we will be getting array1=[D,A,A,T,T,A] as the output from above step.
  4. Once we got the array of characters, then convert the array of characters to array of numbers ie array2=[65,68,78,78,65]. Here numbers indicate equivalent ASCII values.
  5. Let us sort the array in Ascending order.
  6. Then find what is the Highest ASCII value and how many times it is repeated in array2.
  7. Then find the lowest ASCII value in array2.
  8. In final step print the lowst ASCII Value equivalent character N times (N = Number of times Highest ASCII Value is repeated in array).
  9. congrats your done with the above problem !!!
// Java code for ASCII Values problem 

<strong>import java.util.Arrays;

class problem20 {
    public static void main(String[] args) {

        String str="DATTATREYPATIL@12345ttyyutyghfgyrrtg677654";
        char[] arr1=new char[str.length()];
        int[] arr2=new int[str.length()];
        int a;
        int N=0;
        char res;

        // convertion of string to array of characters 

        for(int i=0;i&lt;str.length();i++){
            arr1[i]=str.charAt(i);
        }
        System.out.println(Arrays.toString(arr1));

        // ASCII Array convertion 

        for(int i=0;i&lt;arr1.length;i++){
            arr2[i]=arr1[i];
        }
        System.out.println(Arrays.toString(arr2));

        // sorting the ASCII arrays 
        for(int i=0;i&lt;arr2.length-1;i++){

            if(arr2[i]&gt;arr2[i+1]){

                int temp=arr2[i];
                arr2[i]=arr2[i+1];
                arr2[i+1]=temp;
                i=-1;
            }
        }
        System.out.println(Arrays.toString(arr2));

        //  to finf N which is highest number repetation 

        for(int i=0;i&lt;arr2.length;i++){

            if(arr2[arr2.length-1]==arr2[i]){
                N+=1;
            }
            else{
                continue;
            }
        }
        System.out.println(N);

        //  printing the lowest ASCII value equvivalent character N times 

        for(int i=1;i&lt;=N;i++){

            res=(char)arr2[0];
            System.out.println(res);
        }

       
    }
}</strong>

To get more Explanation of Above code you can visit our channel below

Leave a Comment

Your email address will not be published. Required fields are marked *