Saturday 19 October 2019

Cognizant Technical questions - off campus drives - October 2019

Technical questions
1. What is Relational database?
2. What is liner search?
3. Palindrome program with explanation?
4. what is foreign key?
5. Difference between data mining and data warehouse?
6. what is database?
7. What is primary key?
8. What is binary search?
9. Explain constraints in dbms?
10. Explain data structures?
11. Java basics
12. Sorting techniques
13. String concepts
14. Difference between C and Java
15. bubble sort program in c
16. Write a Insert query?
17. Explain oops concepts?
18. Explain about project
19. prime number program in c
20. arrays ascending order in c

Friday 18 October 2019

ZOHO Coding Round Programs with Answers

1. Given a set of numbers like <10,36,54,89,12> we want to find sum of weights based on the following conditions.
                           1. 5 if a perfect square
                           2. 4 if multiple of 4 and divisible by 6
                           3. 3 if even number
And sort the numbers based on the weight and print it as follows
<10,its weight>, <36,its weight><89,its weight>
Should display the numbers based on increasing order.


2. Print the word with odd letters as
             P                  M
               R             A
                  O     R
                     G
                   O    R
               R           A
             P                M

Program
#include <stdio.h>
#include<string.h>

int main() {
    char s[]="PROGRAM";
    int n=strlen(s);
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            if(i==j || i+j==n-1)
            {
                printf("%c",s[i]);
            }
            else
            {
                printf(" ");
            }
        }
        printf("\n");
    }
   
    return 0;
}

3. Print the elements in anti spiral order
for example
Matrix
1  2  3
4  5  6
7  8  9

output
5 6 9 8 7 4 1 2 3

4. given an array of integers rearrange the array in such a way that the first element is first maximum and second element is first minimum.

Example
Input - {1,2,3,4,5,6,7}
Output - {7,1,6,2,5,3,4}

5. Remove unbalanced parentheses in a given expression.
Example
Input:   ((abc)((de))
Output: ((abc)(de))

Input: (((ab)
Output: (ab)

6.Form a number system with only 3 and 4. Find the nth number of the number system.
Example
3,4,33,34,43,44,333,334,343,344,433,434,443,444 and so on.

7. Check whether a given mathematical expression is valid.
Example
Input:  (a+b)(a*b)         Output: Valid
Input: (ab)(ab+)            Output: Invalid
Input:  ((a+b)                Output: Invalid

8.Write a program to give the following output for the given input:
Example1
Input:  a1b10                output: abbbbbbbbbb
Example2
Input:  b3c6d15            output: bbbccccccddddddddddddddd
The number varies from 1 to 99.

9. Using recursion reverse the string such as:
Example
Input:  alpha beta gamma
Output: gamma beta alpha

10. Given two sorted arrays, merge them such that the elements are not repeated.
Input:
      Array 1 : 2,4,5,6,7,9,10,13
      Array 2 : 2,3,4,5,6,7,8,9,11,15
Output:
      Merged array:
2,3,4,5,6,7,8,9,10,11,13,15


11. Given a string, reverse only vowels in it; leaving rest of the string as it is.
Input:  abcdef
Output: ebcdaf

12. Write a program to determine whether a given number can be expressed as sum of two prime numbers or not.
For example, 34 can be expressed as sum of two prime numbers but 23 cannot be.

13. Given an input string and a dictionary of words, find out if the input string can be segmented into a space-separated sequence of dictionary words. See following examples for more details.
Consider the following dictionary 
{ i, like, sam, sung, samsung, mobile, ice, cream, icecream, man, go, mango} 
Input: ilike 
Output: Yes 
The string can be segmented as "i like". 

Input: ilikesamsung 
Output: Yes
The string can be segmented as "i like samsung"

14. Print the following pattern.
                           1
                         3  2 
                       6  5  4 
                   10  9  8  7 
                   10  9  8  7 
                       6  5  4 
                         3  2
                           1
15. Given an array as input, The condition is if the number is repeated you must add the number and put the next index value to 0. If the number is 0 print it at the last.
Eg: arr[] = { 0, 2, 2, 2, 0, 6, 6, 0, 8} 
      Output: 4 2 12 8 0 0 0 0 0

16. Two strings of equal length will be given. Print all the adjacent pairs which are not equal. 
Input: asdfghij and adsfgijh 
Output: sd-ds, hij-ijh

17. From the input sentence given, find the strings which are not palindrome and print it. 
Input: he knows malayalam 
Output: he knows

18. Given two Strings s1 and s2, remove all the characters from s1 which is present in s2. 
Input: s1=”expErIence”, 
           s2=”En” 
output: s1=”exprIece”

19. Given an array with repeated numbers, Find the top three repeated numbers. 
input: array[]={3, 4, 2, 3, 16, 3, 15, 16, 15, 15, 16, 2, 3} 
output: 3, 16, 15

20. It’s about anagram. input was array of strings .and a word was given to find whether it has anagram in given array. 
Input:  catch, got, tiger, mat, eat, Pat, tap, tea 
Word: ate 
Output: eat, tea