Adobe written test questions answers

Adobe written test questions answers

 Following questions are mainly asked in online test :
What will be the output of the following program?
#include <stdio.h>
int main()
{
    int a[3][3][2] ={{1,2,3,4,5,6},{7,8,9,10,11,12},{13,14,15,16,17,18}};
    printf(“%d %d %d \n”,*(*(*(a+0)+2)+1),*(*(*(a+2)+1)+1),*(a[1][1]+1));
    return 0;
}
PICK ONE OF THE CHOICES
6 15 10
4 15 10
6 16 10
7 14 9
What will be the output of the following program? Assume the array ‘arr’ starts at address 50000
#include <stdio.h>
int main () {
    int arr[] = {89,34,54,68,98};
    printf(“%u %u\n”,arr+1,&arr+1);
}
PICK ONE OF THE CHOICES
50004 50012
50004 50016
50004 50020
50000 50020
What is the correct output of the following program?
#include <stdio.h>
int main() {
    char str1[] = “hello”;
    char str2[] = “hello”;
    if (str1 == str2) printf(“Equal\n”);
    else printf (“Unequal\n”);
    return 0;
}
PICK ONE OF THE CHOICES
Equal
Unequal
Unspecified
Undefined
Which of the following is the correct output for the program given below?
#include <stdio.h>
int main() {
    char *p1 = “The World is”, *p2;
    p2 = p1;
    p1 = “Beautiful”;
    printf (“%s %s\n”,p1,p2);
    return 0;
}
PICK ONE OF THE CHOICES
Beautiful The World is
Beautiful Beautiful
The World is The World is
The World is Beautiful
None of the above
What will be the output of the below program?
#include <stdio.h>
int main() {
    char str[16] = “The World is”;
    str[13] = ‘b’;
    printf (“%s\n”,str);
    return 0;
}
PICK ONE OF THE CHOICES
The World is
The World is b
Garbage
Unspecified
What will be the output of the program if characters ‘hello world’ and enter are supplied to the program?
#include <stdio.h>
int main() {
    void fun();
    fun();
    printf (“\n”);
    return 0;
}
void fun() {
    char c;
    if ((c =getchar()) != ‘\n’)
    fun();
    printf(“%c”, c);
}
PICK ONE OF THE CHOICES
hello world
dlrow olleh
d
ddddddddddd
What will be the output for the following program?
#include <stdio.h>
int main () {
    char *s [] = {“department”,”Information”,”Technology”,”National”};
    char **ptr[] = {s+3,s+1,s+2,s};
    char ***p;
    p = ptr;
    printf (“%s \n”,*(*(p)));
    return 0;
}
PICK ONE OF THE CHOICES
department
National
d
N
int (*funcArr2[10])(float, char, char) = {NULL};
PICK ONE OF THE CHOICES
The above gives syntax error
The above statement declares pointer to array of structures
Valid statement declaring array of function pointers
None of the above
Not a C code
What will be the output of the program?
#include <stdio.h>
#include <stdlib.h>
int main() {
    union A {
      long int y[5];
      union B {
         double g;
         union C {
            int k;
            union D {
                char ch;
                int x[5];
            } s;
         } a;
       } b;
    } *p;
    p = (union A *) malloc (sizeof(union A));
    p->b.a.k = 15;
    printf(” %d %d\n”,p->b.a.s.x[0],p->y[0]);
}
PICK ONE OF THE CHOICES
15 15
15 Garbage
Garbage 15
Garbage Garbage
You are given a function areBracketsMatched which takes a string s (an arithmetic expression) as it’s parameter. Complete the function to check if the arithmetic expression contains matching braces, braces include square brackets and paranthesis as well.Return 1 if it exists, else return 0
Sample Testcases:
—————————-
Input #00:
[(5+4)*{(5/7)-(5+(8/4))}]
Output #00:
1
—————————-
Input #01:
[(5+4])
Output #01:
0
—————————-
Input #02:
[1]
Output #01:
1
—————————-
Input #03:
(2))
Output #03:
0
int areBracketsMatched(string s) {
  vector<char> v;
 for (int i=0; i < s.size(); i++) {
   if (s[i] == ‘(‘ || s[i] == ‘{‘ || s[i] == ‘[‘)
     v.push_back(s[i]);
   else if (s[i] == ‘)’ && v.size() > 0 && v[v.size()-1] != ‘(‘)
     return 0;
     else if (s[i] == ‘}’ && v.size() > 0 && v[v.size()-1] != ‘{‘)
     return 0;
   else if (s[i] == ‘]’ && v.size() > 0 && v[v.size()-1] != ‘[‘)
     return 0;
   if (s[i] == ‘)’ || s[i] == ‘}’ || s[i] == ‘]’)
     v.pop_back();
 }
 if (v.size() == 0)
   return 1;
 return 0;
}
Java runs on a “virtual” stack machine inside JVM, which has instruction of size of one byte (called byte-codes). How many instructions/bytecodes potentially can such a machine have?
PICK ONE OF THE CHOICES
256
Unlimited
2^32 for 32-bit machines
Depends on JVM version
If there are four processes, P1, P2, P3 and P4 needing 1GB, 1.2GB, 2GB and 2GB
of memory to run respectively and they have to be scheduled on a machine which
has 2GB of RAM, the time sharing OS would run this as
PICK ONE OF THE CHOICES
They cannot be loaded into main memory together since sum of required memory exceeds the total memory available – however can be run one after the other.
Cannot be loaded together but can be time sliced, unload and load the next program in a round robin fashion till all terminate.
Load P1 and P2 (since sum of memory required is less than 2GB) and run these by time slicing and then load P3 and finally P4.
All programs can be loaded together and time sliced between these four processes till they all terminate.
In a multi-threaded application, many threads are trying to access the same
resource, say a global count, g. Threads are synchronized by the following code
(assume lock is a static int variable, initialized to 0 (unlocked state)):
if (lock) wait(); // It’s already locked so wait(sleep) till someone wakes me up
else lock=1; // I locked it
/* Critical Section – Increment g */
lock = 0; // Lock released, so wakeup only one of other waiting threads, if any
What is the issue with this synchronization?
PICK ONE OF THE CHOICES
No issues – will work correctly
Works only on a uniprocessor system and would not work on multiprocessor system
Will not work on any system
Cannot say – need more data
In an undirected graph with n vertices and no edges, what is the maximum number of edges that can be added so that the graph remains disconnected?
PICK ONE OF THE CHOICES
NC2
(N-1)C2
N!
(N-1)!
You are given a function multiplyNumbers which takes in 2 integers. Implement the function recursively for multiplying two positive integers using only additions. Make sure you use minimal number of additions which should never be more than the smaller of the two numbers.
Sample Testcases:
Input #00:
3
2
Output #00:
6
int multiplyNumbers(int M,int N){
/*
 For your reference, a function of the prototype int sum(int,int); has already been defined.
When you’re going to sum 2 numbers, use the above function.
For instance to sum up M & N, you can call the function sum(M,N) and it would return M+N.
Please avoid the usage of ‘+’ operator and use the function instead
*/
  if (M == 0) return 0;
  if (M == 1) return N;
  if (N == 0) return 0;
  if (N == 1) return M;
  if (M <= N) {
    return sum(N, multiplyNumbers(M-1, N));
  }
  else {
    return sum(M, multiplyNumbers(M, N-1));
  }
}
You are given a function isSumPossible which takes in an input array and an integer. Return 1, if there exist 2 numbers in the array whose sum is ‘N’, else return 0
NOTE: The array is NOT necessarily in a sorted order
Sample Test Case:
Input #00:
Array:{11,18,21,28,31,38,40,55,60,62}
Required sum(N):66
Output #00:
1
Explanation:
28+38 = 66. There exists a valid combination. Return 1
Input #01:
Array: { 11,18,21,28,31,38,40,55,60,62 }
Required sum (N): 67
Output #01:
0
Explanation:
No possible combination of 2 numbers would lead to a sum of 67
/* Write your custom/own functions here */
#include<algorithm>
bool isSumPossible(vector< int > a , int N) {
 sort(a.begin(), a.end());
  for (int i=0, j=a.size()-1; i < j; ) {
    if (a[i] + a[j] == N) return 1;
    else if (a[i] +a[j] < N) i++;
      else j–;
  }
  return 0;
}
In an undirected graph with n vertices and no edges, what is the maximum number of edges that can be added so that the graph remains disconnected?
PICK ONE OF THE CHOICES
NC2
(N-1)C2
N!
(N-1)!
You are given a function multiplyNumbers which takes in 2 integers. Implement the function recursively for multiplying two positive integers using only additions. Make sure you use minimal number of additions which should never be more than the smaller of the two numbers.
Sample Testcases:
Input #00:
3
2
Output #00:
6
int multiplyNumbers(int M,int N){
/*
 For your reference, a function of the prototype int sum(int,int); has already been defined.
When you’re going to sum 2 numbers, use the above function.
For instance to sum up M & N, you can call the function sum(M,N) and it would return M+N.
Please avoid the usage of ‘+’ operator and use the function instead
*/
  if (M == 0) return 0;
  if (M == 1) return N;
  if (N == 0) return 0;
  if (N == 1) return M;
  if (M <= N) {
    return sum(N, multiplyNumbers(M-1, N));
  }
  else {
    return sum(M, multiplyNumbers(M, N-1));
  }
}
You are given a function isSumPossible which takes in an input array and an integer. Return 1, if there exist 2 numbers in the array whose sum is ‘N’, else return 0
NOTE: The array is NOT necessarily in a sorted order
Sample Test Case:
Input #00:
Array:{11,18,21,28,31,38,40,55,60,62}
Required sum(N):66
Output #00:
1
Explanation:
28+38 = 66. There exists a valid combination. Return 1
Input #01:
Array: { 11,18,21,28,31,38,40,55,60,62 }
Required sum (N): 67
Output #01:
0
Explanation:
No possible combination of 2 numbers would lead to a sum of 67
/* Write your custom/own functions here */
#include<algorithm>
bool isSumPossible(vector< int > a , int N) {
 sort(a.begin(), a.end());
  for (int i=0, j=a.size()-1; i < j; ) {
    if (a[i] + a[j] == N) return 1;
    else if (a[i] +a[j] < N) i++;
      else j–;
  }
  return 0;
}
You are given a function reverseLinkedList which takes in the head pointer of a linked list. Complete the function to reverse the linkedlist and return the head pointer of the reversed linked list.
Sample Testcases:
Input #00:
1->2->3->4
Output #00:
4->3->2->1
node * reverseLinkedList(node *head){
/* For your reference
  struct node{
        node *next;
        int val;
};
typedef struct node node;
You can just start declaring new objects by node *x. It’s already declared
*/
  node* prev   = NULL;
    node* current = head;
    node* next;
    while (current != NULL)
    {
        next  = current->next;
        current->next = prev;
        prev = current;
        current = next;
    }
    return prev;
}
You are given a function isIntegerPalindrome which takes in an integer as its parameter. Complete the function to check if the integer given is a palindrome. If it’s a palindrome, return 1, else return 0
Sample Testcases:
—————————————-
Input #00:
121
Output #00:
1
—————————————-
Input #01:
11
Output #01:
1
int isIntegerPalindrome(int a) {
  int len = log10(a)+1; //cout <<“a=” << a <<  ”  len=” << len;
  int n = a;
  int p = 1;
  for (int i=1; i<len; i++) p *= 10; //cout << “p=” << p;
  while (len > 1) {
    if (n%10 != n/p) return 0;
    n = n%p;
    p /= 100;
    n /= 10;
    len -= 2;
  }
  return 1;
}
You are given a function maxOnes which takes in a 2-d array as its parameter. Each row of the array A consists of 1’s and 0’s such that, in any row, all the 1’s come before any 0’s in that row. Write an efficient algorithm to return the row number of A that contains the most 1’s.
Sample Testcases
—————————-
Input #00:
1
Output #00:
0
—————————-
Input #01:
0 0
1 0
Output #01:
1
int maxOnes(int *a, int N ) {
/* N: size of the array
The array is a row-major contiguous buffer of size N*N,
it’s a 2-D array
*/
  int max=0, maxrow=0;
  for (int i=0; i < N; i++)
    for (int j=max; j < N; j++)
      if (a[i*N+j] == 1) {
        max++;
        maxrow = i;
      }
      else break;
  return maxrow;
}
An integer that has 3 at its unit place has at-least one multiple that has 1 at all places. For example multiple of 3 is 111 and multiple of 13 is 111111. Write a program that prints smallest such multiple of a number taken as input. The multiple can be a large number which may not fit into an int or long.
You are given a function smallestMultiple which takes in an integer as it’s parameter. Complete the function to return the smallest multiple integer.
string smallestMultiple(int a) {
  bool found = false;
  string s = “1”;
  while (!found) {
    string t = s;
    int n = 0;
    for (int i=0; i < t.size(); i++) {
      if (n < a)
        n = n*10 + t[i]-‘0’;
      else
        continue;
      n = n%a;
    }
    if (n == 0) found = true;
    else s += “1”;
  }
  return s;
}

Leave a Reply

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