Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
5,100 views
in Service-based-companies by Expert (107,890 points) | 5,100 views

13 Answers

0 like 0 dislike
Best answer
by Expert (107,890 points)
0 like 0 dislike

Set - 3 : 

22)           Get an unsorted array and convert into alternate array(alternate array- ascending order array by taking alternate elements).Half elements of array in ascending remaining half in descending.The first n elements should be sorted in ascending order and the next part should be sorted in descending and print it

Test Case Input: [1,2,3,4,5,6,7,8],8,4

Output: {1,2,3,4,8,7,6,5}

Function: fn_name(input array, length of array, no of digits to sort (here 3)) Fn_name(input array, 8,4)

 

23)         

Given   5,1,4,7,9....... do alternate sort (odd position sorting) for this..and print

4,5,9

 

24)      Find the occurance of a substring in a parent string 

25)          Write a program to rotate a matrix by 90 degrees.

     
     
     
     
     
     

 

 

29)      Write a program to print numbers in the order of their frequency of occurance. Ip: {1,1,2,2,2,3,4,4,5,5,5,5,5}. Length - 13

Op: {5,5,5,5,5,2,2,2,1,1,4,4,3}

Given Function: int *fn_name(int *arr, int length of array}

 

30)      Write a program to print numbers in the order of their frequency of occurence. Ip: {1,22,333,44,5555,7,8,9,10}. Length - 10

Op: {5555,333,22,44,1,7,8,10}

Given Function: int *fn_name(int *arr, int length of array} Use malloc() function to get the array

 

32)      Write a program to print the not common numbers in both the arrays. Input: Arr1 = {1,2,3,4}

Arr2= {4,5,6,7}

Length = 4

Length = 4

Output: 6

 

33)          Write a program to remove duplicate elements in a array Ip: {1,1,1,1,2,2,2,3,3,4,5}

Op: {1,2,3,4,}

Given Function: int *fn_name(int *arr, int length of array} Use malloc() function to get the input array

 

34)      Copying value to its corresponding index (swap values and index in an array). Input: a[0] = 2; a[1] = 0; a[2] = 3; a[3] = 1; a[4] = 5; a[5] = 4;

Output: a[0] = 1; a[1] = 3; a[2] = 0; a[3] = 2; a[4] = 5; a[5] = 4;

 

35)          Write a program to sort numbers in an array and print the numbers with alternate digits. Use malloc() to get the input array.

Ip: {4,2,5,3,7}

Op: {2,4,7}

 

36)          Create function that passes a @-Dmatrix via a pointer like **a, number of rows, number of colums and flag value. The primary  purpose  of the  program is  to  rotate the matrix of 90 degree (left or right based on the flag 0 or 1 respectively). Return the pointer that shows the altered matrix and print if in the main function.

37)          Create function that passes a a-D-matrix via a pointer like **a, number of rows, number of columns and flag value. The primary purpose of the program is to rotate the matrix by 90 degrees (left or right based on the flag 0 or 1 respectively). Return the pointer that shows the altered matrix and print if in the main function.

 

                             38)          Highest common factor or GCF

                           41)          Pattern Question:-

To print the pattern like for n=3, the program should print : 

 

1 1 1 2

3 2 2 2

3 3 3 4

 

print n=6; n stands for number of lines : 

1111112

3222222

3333334

5444444

5555556

7666666

 

42)           To print the trapezium pattern. for example , we have n=4 the output should be like

1*2*3*4*17*18*19*20

 

 

- -5*6*7*14*15*16

- - - -8*9*12*13

- - - - - -10*11

 

43)          C program to print following pyramid pattern of stars

   
   

 

 

44)         

Write a c program to print Pascal triangle.

In mathematics, Pascal's triangle is a triangular array of the binomial coefficients. In much of the Western world it is named after French mathematician Blaise Pascal, although other mathematicians studied it centuries before him in India, Iran, China, Germany, and Italy.

   
   

 

49)

Get input as N, square the N and generate the number from 1 to N2. N=4

1*2*3*4

9*10*11*12

13*14*15*16

5*6*7*8

 

N=5

1*2*3*4*5

11*12*13*14*15

21*22*23*24*25

16*17*18*19*20

6*7*8*9*10

 

50)   Obtain a output as follows: N=5

1

2*3

4*5*6

7*8*9*10

11*12*13*14*15

11*12*13*14*15

7*8*9*10

4*5*6

 

 

2*3

1

 

51)   Write a C program to print below, when n=4 and s=3

3

44

555

6666

6666

555

44

3

by Expert (107,890 points)
0 like 0 dislike

Set 2 Programs

1)       Test whether an input string of opening and closing parentheses was balanced or not. If yes , return the no. of parentheses. If no, return -1.

2)       Reverse the second half of an input linked list. If the input linked list contained odd number of elements , consider the middlemost element too in the second half. 

3)   Write a program to Merge sort using pointers.

4)   Merge two sorted singly linked lists into one sorted list.

5)   Reverse a linked list using recursion and without recursion

6)       Removal of vowel from string

7)       Print and count all the numbers which are less than a given key element from a given array.

8)       Eliminate repeated letters in Array. Printing non repeating elements in an array and printing the total.

Arr1 = {1,2,3,4,5}    Len1 = 5

Arr 2 = {2,6,8,10}    Len2 = 4

Output = {1,3,4,5,6,8,10}    Total is 7

 

9)       String Reversal

 

10)           Find a target value in a two-dimensional matrix given the number of rows as rowCount and number of columns as columnCount, and return its coordinates. If the value didn't exist, the program had to return (-1,-1).

 

11)          Input: num1 and num2 such that 0 <= num1 <= 99999999 and 0 <= num2

<= 9. You have to find the number of occurences of input num2 in input num1 and return it with the function int isOccured(int num1, int num2).

                                    Example:                                   

 

 

Input: num1= 199294, num2= 0

Output: 3

Test Case 1:

Input:

1222212

2

Expected Output:

5

Test Case 2:

Input:

1001010

0

Expected Output:

4

 

 

12)          Find a sub string in a given string and replace it with another string?

13)           Remove all the vowels from a given string using pointers concept Ip: {a,b,c,d,e,f,g,h,I,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}

Op:

Need to use function call, return value to main function, Pass it as argument

 

14)          Program to check for prime number:

 

15)          To find GCD of two number.

 

16)          Find the GCD of N numbers using pointers

 

17)           Print all the prime numbers which are below the given number separated by comma.

Input: 3

Output: 2,3

 

Ip: 11

Output: 2,3,5,7

 

18)          C program to find out prime factors of given number

 

19)          C Program to Display Prime Numbers between Two Intervals

 

20)          C Program to Display Armstrong Number Between Two Intervals

 

 

 

21)           Write a function to return a sorted array after merging two unsorted arrays, the parameters will be two integer pointers for referencing arrays and two int variable, the length of arrays (Hint: use malloc() to allocate memory  for  3rd array):

 

 

by Expert (107,890 points)
0 like 0 dislike
Set 1 - Programs
 
0. Write a C program, to find the area of a circle when the diameter is given. The input diameter is an integer and the output area should be a floating point variable with 2 point precision.

1.     Write a c program, to check whether the given tear is a  leap  year or not. A leap year is a calendar year containing one additional day(Feb 29th)added to keep the calendar year synchronized with the astronomical year.

 
2.     Write a C program to find the GCD of the given 2 numbers. The input is 2 integers and the output GCD also should be an integer value.
 
3.     Write a C program which will check whether a given year YYYY is a leap yer. A leap year is exactly divisible by 4 except for century years(years ending with 00). The century year is a leap year only if its perfectly divisible by 400. If the given year is not a leap year, then print NO to stdout. Note that the words YES and NO have to be printed in UPPERCASR(capital letters) Other than the word YES or NO, no other extra information shoul be printed to stdout.
EXAMPLE :
Given input “1990”, here YYYY is 1990, expected output is NO
 4.     Factorial program in C.
Factorial of a non-negative integer , denoted by n1, is the product of all positive integers less than or equal to n.
For example, The value of 5! Is 5*4*3*2*1=120
 5.     C program question to find the hypotenuse of a right angle triangle when the other 2 sides are given.
 6.  Write a C program to calculate the factorial of a non negative integer N. The factorial of a number N is defined as the product of all integers from 1 up to N. Factorial of 0 is defined to be 1. The number N is a non negative integer that will be passed to the program. Write the output to stdout formatted as an integer WITHOUT any other additional text. You may assume that the input integer will be such that the output will not exceed the largest possible integer that can be stored in an int type variable.
7. Write a C program to find the area of a triangle given the base and the corresponding height. The values base and height are both positive integers passed to the program as the first and second parameters respectively. Write the output to stdout formatted as a floating point number  rounded  to  EXACTLY  2 decimal precision WITHOUT any other additional text. Scientific format(such as 1.00E+5) should NOT be used while  printing  the  output.  You  may  assume  that  the  inputs will be such that the output will not exceed the largest possible real number that can be stored in a float type variable.

1.
Write a C program to find the area of a triangle given the base and the corresponding height. The values base and height are both positive integers passed to the program as the first and second parameters respectively. Write the output to stdout formatted as a floating point number  rounded  to  EXACTLY  2 decimal precision WITHOUT any other additional text. Scientific format(such as 1.00E+5) should NOT be used while  printing  the  output.  You  may  assume  that  the  inputs will be such that the output will not exceed the largest possible real number that can be stored in a float type variable.

 
 
 
2.  Write a C program that will find the sum of all prime no. in a given range. The range will be specified as parameters. The first parameter, N1 which is a positive integer, will contain the lower bound of the range. The second parameter N2, which is also a positive integer, will contain the upper bound of the range. The program should consider all the prime no. within the range, excluding the upper and lower bound in the output in integer format to stdout. Other than the integer number ,no other extra information should be printed to stdout. Other than the integer number
,no other extra information should be printed to stdout
Example: input “7” and “24”, here N1=7 and N2=34, expected output is 83
 
3.      
Write a C program which will convert a given binary number N to its decimal equivalent. The given binary number N will be passed to the program using the first parameter. Print the equivalent decimal number to stdout in integer format. Otherwise the decimal number, no other extra information should be printed to stdout.
Example : Given input “111001”, here N=111001, expected output 57
 
4.        Write a C program which will check a given number N is a palindrome. An integer is a palindrome if the reverse number is equal to the original number. The given number N will be a positive 5 digit number and will be passed to the program using the final parameter. If the given number is a palindrome, then print the word YES to stdout. If the given number is not a palindrome, then print NO as stdout. Note that the words YES/NO have to be in UPPERCASE (capital letters). Other than the words YES or NO, no other extra information should be printed to stdout.
Example: Given input 53435.here N=53435.expected out is YES if it is palindrome. Write your code?
 
5.       Check if input string is palindrome or not
 
6.       Program: You need to get an input number from user then check whether the no. is
prime no. or not ...if it is prime no. need print the square root of a no. else print
0.00. eg 7 means the op is 2.65.

 
7.       Given the diameter of a circle, find the area of the circle.
8.       Print Fibonacci series upto N terms
9.       Write a code for finding n! (calculate the factorial of a number)
10.  addition of two numbers and converting the result to binary
11.  Find if a given year is a leap year.
12.  Printing reverse for digits. Float values, you need to round up
13.  string reversal(digits and char)
14.  reverse of a string program in c without using string functions.
15.  sum of odd numbers in between the range of two numbers (7 to 24).
16.  Check if the input number is a perfect number or not.
17.  binary to decimal
18.  5 Factorial (In the factorial one there was 1 private test case that is ( 0! is 1 ) then the compiler goes on and calculates for 3 Public Cases ( 3!=6, 4! = 24, 5! = 120
) as soon as it gets those results.)
19.  Armstrong Number
20.  Temperature conversion
21.  Find whether the given number is prime or not. If prime then print its square root if not then print 0.00
22.  String compare without using strcmp
23.  Largest or second largest number in N INPUT numbers.
24. GCD OF TWO NUMBERS.
25. LCM OF TWO NUMBERS.
26. AREA OF TRIANGLE GIVEN A,B,C.
27. SORT AN ARRAY INTO TWO HALVES , ONE HALVE IN ASCENDING ORDER , OTHER IN DESCENDING ORDER.
28. SQUARE ROOT OF NUMBER WITHOUT USING SQUARE ROOT.H LIBRARY.
29. NTH FIBONACCI NUMBER.
by Expert (107,890 points)
0 like 0 dislike
1)Write code for selection sort algorithm.

2)Write code for bubble sort algorithm.

3)Write code for Longest Increasing Subsequence Algorithm.

4)Convert decimal number to octal number.

5)Convert binary number to octal number.

6)Write a program to remove vowels from the string.
by Expert (107,890 points)
0 like 0 dislike
1)Write program for binary search.

2)Print all unique elements of the array.
by Expert (107,890 points)
0 like 0 dislike
1)Find gcd of two numbers.

2)Find lcm of two numbers.

3)Find whether the given number is armstrong number or not.

4)Find area of triangle given the base and height.
by Expert (107,890 points)
0 like 0 dislike
1)Find the factorial of a number.

2)Write a Program to find the area of a circle.

#include <bits/stdc++.h>

#define PI 3.14

int main()

{

float d, area;

scanf("%f",&d);

area=PI*(d/2)*(d/2);

printf("%0.2f", area);

return 0;

}
by Expert (107,890 points)
0 like 0 dislike
1)Program to check wether the given alphabet is consonant or vowel.

2)Program to check if given number is prime or not.

3)Findd the most occurring character in the given string.
by Expert (107,890 points)
0 like 0 dislike

CODING QUESTION

Given an array, find the most frequent element in it. If there are multiple elements that appear maximum number of times, print any one of them. Take input from STDIN.

Examples:

Input: arr[] = {1, 3, 2, 1, 4, 1}

Output: 1

1 appears three times in array which is maximum frequency.

Input: arr[] = {10, 10, 20, 10, 20, 30, 20}

Output: 20

Both 10 and 20 appears three times which is maximum. So display either 10 or 20.

 

Solution: (Java Coding)


import java.util.*;

class Test {

    static int mostFrequent(int arr[], int n)

    {

         

        // Sort the array

        Arrays.sort(arr);

        // find the max frequency using linear

        // traversal

        int max_count = 1, res = arr[0];

        int curr_count = 1;

         

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

        {

            if (arr[i] == arr[i - 1])

                curr_count++;

            else

            {

                if (curr_count > max_count)

                {

                    max_count = curr_count;

                    res = arr[i - 1];

                }

                curr_count = 1;

            }

        }

        // If last element is most frequent

        if (curr_count > max_count)

        {

            max_count = curr_count;

            res = arr[n - 1];

        }

     

        return res;

    }

    public static void main (String[] args) {

         

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

        int n = arr.length;

        System.out.println(mostFrequent(arr,n));

         

    }

}
by Expert (107,890 points)
0 like 0 dislike

Q6 : Write a C program to calculate the factorial of a non-negative integer N. The factorial of a number N is defined as the product of all integers from 1 up to N. Factorial of 0 is defined to be 1. The number N is a non-negative integer that will be passed to the program as the first command line parameter. Write the output to stdout formatted as an integer WITHOUT any other additional text. You may assume that the input integer will be such that the output will not exceed the largest possible integer that can be stored in an int type variable. FIND….

 

Q7: Write a C program to find the area of a triangle given the base and the corresponding height. The values base and height are both positive integers passed to the program as the first and second command line parameters respectively. Write the output to stdout formatted as a floating point number rounded to EXACTLY 2 decimal precision WITHOUT any other additional text. Scientific format(such as 1.00E+5) should NOT be used while printing the output. You may assume that the inputs will be such that the output will not exceed the largest possible real number that can be stored in a float type variable

by Expert (107,890 points)
0 like 0 dislike

Question 3: Write a loop statement that will show the following output:

1

12

123

1234

12345

Answer:

for (a=1; a<=5; i++)

{

for (b=1; b<=a; b++){

printf("%d",b);

}

printf("\n");

}

Question 4: Tell how to check whether a linked list is circular. Answer: Create two pointers, each set to the start of the list.

Update each as follows: while (pointer1) { pointer1 = pointer1->next; pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next; if (pointer1 == pointer2) { print ("circular\n"); } }

Question 5: Write a program to swap two numbers without using a temporary variable.

Answer: void swap(int &i, int &j) { i=i+j; j=i-j; i=i-j

 

 

by Expert (107,890 points)
0 like 0 dislike

Question 1 : 

Consider the following series: 1,1,2,3,4,9,8,27,16,81,32,243,64,729,128,2187…

 

This series is a mixture of 2 series - all the odd terms in this series form a geometric series and all the even terms form yet another geometric series. Write a program to find the Nth term in the series.

 

The value N in a positive integer that should be read from STDIN. The Nth term that is calculated by the program should be written to STDOUT. Other than value of n th term,no other character / string or message should be written to STDOUT. For example , if N=16, the 16th term in the series is 2187, so only value 2187 should be printed to STDOUT.

 

You can assume that N will not exceed 30.

 

Answer:

 

#include #include


int main()


{

//code int n;

scanf("%d", &n); if(n % 2 == 1)

{

int a = 1; int r = 2;

int term_in_series = (n+1)/2;

int res = pow(2, term_in_series - 1); printf("%d ", res);

}

else

{

int a = 1; int r = 3;


int term_in_series = n/2;

int res = pow(3, term_in_series - 1); printf("%d ", res);

}


return 0;

}

Question 2 : 

Write a program to find the nth term in this series.

 

The value n in a positive integer that should be read from STDIN the nth term that is calculated by the program should be written to STDOUT. Other than the value of the nth term no other characters /strings or message should be written to STDOUT.

 

For example if n=10,the 10 th term in the series is to be derived from the 9th term in the series. The 9th term is 8 so the 10th term is (8/2)=4. Only the value 4 should be printed to STDOUT.

 

You can assume that the n will not exceed 20,000.

 

Code:

 

#include #include


int main() {

//code int n;

scanf("%d", &n); if(n % 2 == 1)

{

int a = 1; int r = 2;

int term_in_series = (n+1)/2;

int res = 2 * (term_in_series - 1); printf("%d ", res);

}

else

{

int a = 1; int r = 3;

int term_in_series = n/2;


int res = term_in_series - 1; printf("%d ", res);

}


return 0;

}
by Expert (107,890 points)