SANDS Technologies Fresher Interview Questions with Answers

SANDS Technologies Fresher Interview Questions with Answers 

This blog explains about SANDS Technologies Fresher Interview Questions with Answers and is given below : 

1.Remove Duplicates in this string “coconut”

// CPP program to remove duplicate character

// from character array and print in sorted

// order

#include <bits/stdc++.h>

using namespace std;

 

char *removeDuplicate(char str[], int n)

{

   // Used as index in the modified string

   int index = 0;   

 

   // Traverse through all characters

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

 

     // Check if str[i] is present before it  

     int j;  

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

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

           break;

 

     // If not present, then add it to

     // result.

     if (j == i)

        str[index++] = str[i];

   }

 

   return str;

}

 

// Driver code

int main()

{

   char str[]= “geeksforgeeks”;

   int n = sizeof(str) / sizeof(str[0]);

   cout << removeDuplicate(str, n);

   return 0;

}

Output:

geksfor

Time Complexity : O(n * n)
Auxiliary Space : O(1)
Keeps order of elements same as input.

 

2. Pattern

a

B c

d E f

G h I j

K l M n O

Program

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

#include<stdio.h>

 

void main()

{

    int i,j,n;

 

    printf(“Enter the no of lines\n”);

    scanf(“%d”,&n);

 

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

    {

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

        {

            printf(“%c”,(char)(j+64));

        }

 

        printf(“\n”);

    }

}

 

Output

 

3. How many Times String “RAJASTHAN” can be arranged

// Java program to find number of distinct

// permutations of a string.

public class GFG {

 

    static final int MAX_CHAR = 26;

 

    // Utility function to find factorial of n.

    static int factorial(int n)

    {

        int fact = 1;

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

            fact = fact * i;

        return fact;

    }

 

    // Returns count of distinct permutations

    // of str.

    static int countDistinctPermutations(String str)

    {

        int length = str.length();

 

        int[] freq = new int[MAX_CHAR];

 

        // finding frequency of all the lower case

        // alphabet and storing them in array of

        // integer

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

            if (str.charAt(i) >= ‘a’)

                freq[str.charAt(i) – ‘a’]++;

 

        // finding factorial of number of appearances

        // and multiplying them since they are

        // repeating alphabets

        int fact = 1;

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

            fact = fact * factorial(freq[i]);

 

        // finding factorial of size of string and

        // dividing it by factorial found after

        // multiplying

        return factorial(length) / fact;

    }

 

    // Driver code

    public static void main(String args[])

    {

        String str = “fvvfhvgv”;

        System.out.println(countDistinctPermutations(str));

    }

}

 

4. Sum of digits using Recursion

// Recursive java program to 

// find sum of digits of a number

import java.io.*;

 

class sum_of_digits

{

    // Function to check sum 

    // of digit using recursion

    static int sum_of_digit(int n)

    { 

        if (n == 0)

            return 0;

        return (n % 10 + sum_of_digit(n / 10));

    }

 

    // Driven Program to check above

    public static void main(String args[])

    {

        int num = 12345;

        int result = sum_of_digit(num);

        System.out.println(“Sum of digits in ” + 

                           num + ” is ” + result);

    }

}

 

Output:

Sum of digits in 12345 is 15

   5.|1 2 3|

    |4 5 6|

    |7 8 9|

How you convert this matrix into

|1 2 3 4 5 6 7 8 9|

// Java implementation to 

// sort the given matrix

import java.io.*;

import java.util.*;

 

class GFG {

 

    static int SIZE = 10;

 

    // function to sort the given matrix

    static void sortMat(int mat[][], int n)

    {

        // temporary matrix of size n^2

        int temp[] = new int[n * n];

        int k = 0;

 

        // copy the elements of matrix 

        // one by one into temp[]

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

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

                temp[k++] = mat[i][j];

 

        // sort temp[]

        Arrays.sort(temp);

 

        // copy the elements of temp[]

        // one by one in mat[][]

        k = 0;

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

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

                mat[i][j] = temp[k++];

    }

 

    // function to print the given matrix

    static void printMat(int mat[][], int n)

    {

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

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

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

            System.out.println();

        }

    }

 

    // Driver program to test above

    public static void main(String args[])

    {

        int mat[][] = { { 1, 2, 3 },

                        { 4, 5, 6 },

                        { 7, 8, 9 } };

        int n = 3;

 

        System.out.println(“Original Matrix:”);

        printMat(mat, n);

 

        sortMat(mat, n);

 

        System.out.println(“Matrix After Sorting:”);

        printMat(mat, n);

 

    }

}

 

Output :

Original Matrix:

1 2 3

4 5 6

7 8 9

6. Print the Alphabets which is in the prime number index

// Java Program to print 

// Characters at Prime index 

// in a given String

class GFG

{

    static boolean isPrime(int n)

    {

        // Corner case

        if (n <= 1) return false;

 

        // Check from 2 to n-1

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

            if (n % i == 0)

                return false;

 

        return true;

    }

 

    // Function to print 

    // character at prime index

    static void prime_index(String input)

    {

        int n = input.length();

 

        // Loop to check if 

        // index prime or not

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

            if (isPrime(i)) 

 

                System.out.print

                (input.charAt(i – 1));         

    }

 

    // Driver code 

    public static void main (String[] args)

    {

        String input = “GeeksforGeeks”;

 

        prime_index(input);

    }

}

 

// This code is contributed by Anant Agarwal.

Output :

eesoes

REFERENCES : 

https://www.geeksforgeeks.org/remove-duplicates-from-a-given-string/

https://codedost.com/c/character-alphabet-patterns-c/

https://codedost.com/c/character-alphabet-patterns-c/c-program-characteralphabet-pattern-5/

https://www.geeksforgeeks.org/number-distinct-permutation-string-can/

https://www.geeksforgeeks.org/sum-digit-number-using-recursion/

https://www.geeksforgeeks.org/sort-given-matrix/

https://www.geeksforgeeks.org/program-print-characters-present-prime-index-given-string/