Minuscule Technologies Fresher Interview Questions

Minuscule Technologies Fresher Interview Questions 

This blog explains about Minuscule Technologies Pvt . Ltd . Fresher Interview Questions and is given below :

 

1.Write a program to find second largest number in an array, without sorting.

// JAVA Code for Find Second largest

// element in an array

class GFG {

 

    /* Function to print the second largest

    elements */

    public static void print2largest(int arr[], 

                                     int arr_size)

    {

        int i, first, second;

 

        /* There should be atleast two elements */

        if (arr_size < 2)

        {

            System.out.print(” Invalid Input “);

            return;

        }

 

        first = second = Integer.MIN_VALUE;

        for (i = 0; i < arr_size ; i++)

        {

            /* If current element is smaller than 

            first then update both first and second */

            if (arr[i] > first)

            {

                second = first;

                first = arr[i];

            }

 

            /* If arr[i] is in between first and 

               second then update second  */

            else if (arr[i] > second && arr[i] != first)

                second = arr[i];

        }

 

        if (second == Integer.MIN_VALUE)

             System.out.print(“There is no second largest”+

                                 ” element\n”);

        else

             System.out.print(“The second largest element”+

                                      ” is “+ second);

    }

 

    /* Driver program to test above function */

    public static void main(String[] args) 

    {

            int arr[] = {12, 35, 1, 10, 34, 1};

            int n = arr.length;

            print2largest(arr, n);

    }

}

Output:

The second largest element is 34

 

2. Write program to find number of line, word and characters available in a paragraph/file.

// Java program to count the 

// number of charaters in a file

import java.io.*;

 

public class Test

{

    public static void main(String[] args) throws IOException

    {

        File file = new File(“C:\\Users\\Mayank\\Desktop\\1.txt”);

        FileInputStream fileStream = new FileInputStream(file);

        InputStreamReader input = new InputStreamReader(fileStream);

        BufferedReader reader = new BufferedReader(input);

 

        String line;

 

        // Initializing counters

        int countWord = 0;

        int sentenceCount = 0;

        int characterCount = 0;

        int paragraphCount = 1;

        int whitespaceCount = 0;

 

        // Reading line by line from the 

        // file until a null is returned

        while((line = reader.readLine()) != null)

        {

            if(line.equals(“”))

            {

                paragraphCount++;

            }

            if(!(line.equals(“”)))

            {

 

                characterCount += line.length();

 

                // \\s+ is the space delimiter in java

                String[] wordList = line.split(“\\s+”);

 

                countWord += wordList.length;

                whitespaceCount += countWord -1;

 

                // [!?.:]+ is the sentence delimiter in java

                String[] sentenceList = line.split(“[!?.:]+”);

 

                sentenceCount += sentenceList.length;

            }

        }

 

        System.out.println(“Total word count = ” + countWord);

        System.out.println(“Total number of sentences = ” + sentenceCount);

        System.out.println(“Total number of characters = ” + characterCount);

        System.out.println(“Number of paragraphs = ” + paragraphCount);

        System.out.println(“Total number of whitespaces = ” + whitespaceCount);

    }

}

Output:

Total word count = 5

Total number of sentences = 3

Total number of characters = 21

Number of paragraphs = 2

Total number of whitespaces = 7

3. Program to find summation of integer number (for e.g, input = 8973 8+9+7+3 = 27 = 2+7 = 9 output should be  9)

// Java Program to find sum of series

import java.io.*;

 

class GFG {

 

    // Function to return sum of

    // 1/1 + 1/2 + 1/3 + ..+ 1/n

    static double sum(int n)

    {

      double i, s = 0.0;

      for (i = 1; i <= n; i++)

          s = s + 1/i;

      return s;

    }

 

 

    // Driven Program

    public static void main(String args[])

    {

        int n = 5;

        System.out.printf(“Sum is %f”, sum(n));

 

    }

}

 

// This code is contributed by Nikita Tiwari.

Output:

2.283333

Type 2

#include<stdio.h>

int main(){

  int num,sum=0,r;

  printf(“Enter a number: “);

  scanf(“%d”,&num);

  while(num){

      r=num%10;

      num=num/10;

      sum=sum+r;

  }

  printf(“Sum of digits of number:  %d”,sum);

  return 0;

}

Sample output:

Enter a number: 123

Sum of digits of number:  6

 

 

4. Print astriks in pyramid format, input should be number of rows

                    *

                  * * *

                * * * * *

              * * * * * * *

// Java code to demonstrate star pattern

public class GeeksForGeeks

{

    // Function to demonstrate printing pattern

    public static void printTriagle(int n)

    {

        // outer loop to handle number of rows

        //  n in this case

        for (int i=0; i<n; i++)

        {

 

            // inner loop to handle number spaces

            // values changing acc. to requirement

            for (int j=n-i; j>1; j–)

            {

                // printing spaces

                System.out.print(” “);

            }

 

            //  inner loop to handle number of columns

            //  values changing acc. to outer loop

            for (int j=0; j<=i; j++ )

            {

                // printing stars

                System.out.print(“* “);

            }

 

            // ending line after each row

            System.out.println();

        }

    }

 

    // Driver Function

    public static void main(String args[])

    {

        int n = 5;

        printTriagle(n);

    }

}

Output:

    *

   * *

  * * *

 * * * *

* * * * *

 

 

5. Find a String is palindrome or not? (for eg “MALAYALAM” – Reverse of string also give same value)

// Java program to find if given 

// string is K-Palindrome or not

class GFG 

{

 

    // find if given string is

    // K-Palindrome or not

    static int isKPalDP(String str1, 

            String str2, int m, int n) 

    {

 

        // Create a table to store 

        // results of subproblems

        int dp[][] = new int[m + 1][n + 1];

 

        // Fill dp[][] in bottom up manner

        for (int i = 0; i <= m; i++) 

        {

            for (int j = 0; j <= n; j++) 

            {

 

                // If first string is empty,

                // only option is to remove all

                // characters of second string

                if (i == 0) 

                {

                    // Min. operations = j

                    dp[i][j] = j; 

                } 

 

                // If second string is empty, 

                // only option is to remove all

                // characters of first string

                else if (j == 0) 

                {

                    // Min. operations = i

                    dp[i][j] = i; 

                } 

 

                // If last characters are same, 

                // ignore last character and

                // recur for remaining string

                else if (str1.charAt(i – 1) ==

                        str2.charAt(j – 1)) 

                {

                    dp[i][j] = dp[i – 1][j – 1];

                } 

 

                // If last character are different,

                //  remove it and find minimum

                else 

                {

                    // Remove from str1

                    // Remove from str2

                    dp[i][j] = 1 + Math.min(dp[i – 1][j], 

                            dp[i][j – 1]); 

                }

            }

        }

        return dp[m][n];

    }

 

    // Returns true if str is k palindrome.

    static boolean isKPal(String str, int k)

    {

        String revStr = str;

        revStr = reverse(revStr);

        int len = str.length();

 

        return (isKPalDP(str, revStr,

                len, len) <= k * 2);

    }

 

    static String reverse(String str)

    {

        StringBuilder sb = new StringBuilder(str);

        sb.reverse();

        return sb.toString();

    }

 

    // Driver program

    public static void main(String[] args) 

    {

        String str = “acdcb”;

        int k = 2;

        if (isKPal(str, k)) 

        {

            System.out.println(“Yes”);

        } 

        else 

        {

            System.out.println(“No”);

        }

    }

}

 

// This code is contributed by

// PrinciRaj1992

Output :

Yes

 

6.How to find the first non repeated character of a given String

// Java program to find first non-repeating character

 

class GFG 

{

    static final int NO_OF_CHARS = 256;

    static char count[] = new char[NO_OF_CHARS];

 

    /* calculate count of characters 

       in the passed string */

     static void getCharCountArray(String str) 

     {

         for (int i = 0; i < str.length();  i++)

              count[str.charAt(i)]++;

     }

 

    /* The method returns index of first non-repeating

       character in a string. If all characters are repeating 

       then returns -1 */

    static int firstNonRepeating(String str)

    {

        getCharCountArray(str);

        int index = -1, i;

 

        for (i = 0; i < str.length();  i++)

        {

            if (count[str.charAt(i)] == 1)

            {

                index = i;

                break;

            }   

        }  

 

      return index;

    }

 

    // Driver method

    public static void main (String[] args)

    {

        String str = “geeksforgeeks”;

        int index =  firstNonRepeating(str);

 

        System.out.println(index == -1 ? “Either all characters are repeating or string ” +

                   “is empty” : “First non-repeating character is ” +  str.charAt(index));

    }

}

Output:

First non-repeating character is f

 

7. In an array 1-100 multiple numbers are duplicates, how do you find it.

class RepeatElement 

{

    void printRepeating(int arr[], int size) 

    {

        int i, j;

        System.out.println(“Repeated Elements are :”);

        for (i = 0; i < size; i++) 

        {

            for (j = i + 1; j < size; j++) 

            {

                if (arr[i] == arr[j]) 

                    System.out.print(arr[i] + ” “);

            }

        }

    }

 

    public static void main(String[] args) 

    {

        RepeatElement repeat = new RepeatElement();

        int arr[] = {4, 2, 4, 5, 2, 3, 1};

        int arr_size = arr.length;

        repeat.printRepeating(arr, arr_size);

    }

}

Output :

Repeating elements are 4 2

 

 

8.How do you count a number of vowels and consonants in a given string?

  1. publicclass CountVowelConsonant {  

  2. public static void main(String[] args) {  

  3. //Counter variable to store the count of vowels and consonant  
  4. int vCount = 0, cCount = 0;  
  5. //Declare a string  
  6. String str = “This is a really simple sentence”;  
  7. //Converting entire string to lower case to reduce the comparisons
  8. str = str.toLowerCase();  
  9. for(inti = 0; i < str.length(); i++) {  
  10. //Checks whether a character is a vowel
  11. if(str.charAt(i) == ‘a’|| str.charAt(i) == ‘e’ || str.charAt(i) == ‘i’ || str.charAt(i) == ‘o’ || str.charAt(i) == ‘u’) {  
  12. //Increments the vowel counter
  13. vCount++;  
  14. }  
  15. //Checks whether a character is a consonant
  16. elseif(str.charAt(i) >= ‘a’ && str.charAt(i)<=’z’) {    
  17. //Increments the consonant counter
  18. cCount++;  
  19. }  
  20. }  
  21. out.println(“Number of vowels: “+ vCount);  
  22. out.println(“Number of consonants: “+ cCount);  
  23. }  
  24. }  

Output:

Number of vowels: 10

Number of consonants: 17

 

 

9.Write a program to find fibbonaci and factorial using recurssion.Ra

 

/*

* C Program to print fibonacci series using recursion

*/

#include <stdio.h>

#include <conio.h>

 

int fibonacci(int term);

int main(){

    int terms, counter;

    printf(“Enter number of terms in Fibonacci series: “);

    scanf(“%d”, &terms);

    /*

     *  Nth term = (N-1)th therm + (N-2)th term;

     */

    printf(“Fibonacci series till %d terms\n”, terms);

    for(counter = 0; counter < terms; counter++){

        printf(“%d “, fibonacci(counter));

    }

    getch();

    return 0;

}

/*

 * Function to calculate Nth Fibonacci number

 * fibonacci(N) = fibonacci(N – 1) + fibonacci(N – 2);

 */

int fibonacci(int term){

    /* Exit condition of recursion*/

    if(term < 2)

       return term;

    return fibonacci(term – 1) + fibonacci(term – 2);

}

Program Output

Enter number of terms in Fibonacci series: 9

Fibonacci series till 9 terms

0 1 1 2 3 5 8 13 21

REFERENCES : 

https://www.geeksforgeeks.org/find-second-largest-element-array/

 

https://www.geeksforgeeks.org/counting-number-lines-words-characters-paragraphs-text-file-using-java/

 

https://www.cquestions.com/2010/06/write-c-program-to-find-out-sum-of.html

 

https://www.geeksforgeeks.org/programs-printing-pyramid-patterns-java/

 

https://www.geeksforgeeks.org/find-if-string-is-k-palindrome-or-not/

 

https://www.geeksforgeeks.org/given-a-string-find-its-first-non-repeating-character/

 

https://www.geeksforgeeks.org/find-the-two-repeating-elements-in-a-given-array/

 

https://www.javatpoint.com/program-to-count-the-total-number-of-vowels-and-consonants

 

https://www.techcrashcourse.com/2015/03/c-program-fibonacci-series-using-recursion.html