## C# Interview Questions

- 0of 0 votes
If I need to read .txt file (inside +4000 words) and print 100 most repeated which structure is the easiest:

hash table?

binary tree?

linked list?

Thanks

- 0of 0 votes
The question which has been asked to me is : Print right angle triangle with stars(*) without nested loops. Implement in C programming language.

- 0of 0 votes
Implement zad-off-chu sequence for LTE eNodeB in c language?

- 0of 0 votes
write a program that take l and r as input and display the number of prime numbers that lie between l and r(l and r inclusive) and can be represented as sum of two consecutive prime numbers +1

- 0of 0 votes
Reverse Linked List

- 0of 0 votes
Write a program to find the number of ways can one climb a staircase with 'n' steps, taking one or two steps at a time.

- 0of 0 votes
write a program to add all the non-diagonal elements of a 2D array.

- 0of 0 votes
f(n)=n⁄2 when n is even;f(n)=f(3n+1)when n is odd. Write recursive function to compute f(n).

- 0of 0 votes
A program P reads in 500 integers in the range (0,100) representing the scores of 500 students. It then prints the frequency of each score above 50. Implement program P in C language.

- 0of 0 votes
There are four coins a , b , c , d out of which three coins are of equal weight and one coin is heavier. Write a C program to find the heavier coin.

- 0of 0 votes
Write a C program to check biggest among two numbers without using any relational operators

- 0of 0 votes
Please post me full explanation(not only answer)

I want to know how it works.`#include<stdio.h> void main() { int x=1, y=8, z; z= ++y + ++x + ++x; printf("z=%d", z); }`

- 0of 0 votes
what is output for below code and what is purpose of using const type for pointer variable p?

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

char a[10]="HELLO";

char *const p=a;

clrscr();

//puts(p);

printf("%s",p);

*p='n';

//puts(p);

printf("%s",p);

getch();

}

- 0of 0 votes
Int a=10;

Int b=a>15;

Print("%d",b);

a)15

b)10

c)0

d)1

- 1of 1 vote
#define mysizeof(x) (char*)(&x+1)-(char*)(&x)

//why casting is done to char* for mysizeof

// casting it to void also works

- 1of 1 vote
Given a string containing only 0 and 1's, write a function that reverses and returns the two complements of the string.

- 0of 0 votes
Implement a Qsort similar to the build in one in C, but use an insertion sort instead

void GoogleSort(void *ptr, int number, int SIZE, int (*functionp)(const void *, const void *)) {

}

- 0of 0 votes
Write a C program to find given number is even or odd without using any control structures like conditional statements or loops.

- 0of 0 votes
write a program to accept a value for 4x4 matrix. find the total of matrix, minimum and maximum number in matrix

- -2of 2 votes
#include<stdio.h>

#include<string.h>

char* minimumCost(char* input1[],int input2)

{

- -3of 3 votes
#include<stdio.h>

#include<string.h>

char* minimumCost(char* input1[],int input2)

{

- 0of 0 votes
how to find all paths of a graph?

hi ,

i have a directed graph as an input and i want to find in that graph subGraphs that fit to some path

for example : i have the following graph 1[E] ->2[E] ->3[M]->4[E]->5[M]->6[M]->7[E]->8[M] .and i have the path E->M->E

then the program output should be the subGraph 2->3->4

note that the solution should be implemented as ADJ Matrix

the Graph is directed DAG

the program should be with C language

- 0of 0 votes
To find 5th prime number after 3. suppose input is 3 5 output should be 17

#include <stdio.h>

int main(void) {

int x;

for(; scanf("%d",&x) > 0 && x != 42; printf("%d\n", x));

return 0;

}

- 0of 0 votes
Implement a method for the following signature:

`void * alignedAllocate(size_t sizeInBytes, size_t alignment) { }`

The method should allocate memory for the given size and the pointer should be aligned.

For example if`p = alignedAllocate(1000,64);`

p%8 should be 0.

Implement a second method that deleted the pointer give p.

Extend the delete method to handle multiple p's.

- 0of 0 votes
Write a function which will sort a linked list efficiently. I explain merge sort, However interviewer was not agree with my answer.

Interviewer was expecting answer bubble sort along with backtracking. Not convinced or agreed with his opinion though.

- 0of 0 votes
What does the error "Null Pointer Assignment" mean and what causes this error ?

If found, what are basic approaches to debug this type of error ?

- 0of 0 votes
Insert a value into a sorted linked list.

Using C/C++ write a small function (around 5 lines in the body) to insert a value in a sorted linked list. Take into consideration that the list might be empty at first, and the function should cover the cases of insertion at the head and tail...

PS what the interviewer is looking for is the ability to write a small C/C++ code that solves the question and not the algorithm per se which is trivial

- 0of 0 votes
GLaDOS is feeling bored, so she decided to come up with a board game. The game is as follows. There is

board of dimension n x n (2 <= n <= 10). Each position in this board is either a 0 or a power of 2, between 2

and 2048. Once the board is set up, there are only two moves allowed - move all left or move all right.

The way move all left works is as follows:

For every row on the board, starting from the rightmost position each element is moved to its left. An

element with a zero value does not move. An element with non-zero value can move to its left if the value of

the element to its left is a 0 or has the same value as the current element.

In case, the element to the left is 0 then the element and 0 swap positions i.e., 4 0 0 4 would become 4 0 4 0

In case, the element to the left has the same value as the current element then the left element combines

with its right element and creates an element with double the value in place of the right element and leaves

a 0 in its current place. For e.g., 2 2 would become 4 0 or 2 2 2 2 would become 4 0 4 0.

The combining operation can cause a cascading operation i.e., if the new element created has the same

value as the element to its left, it can combine again.

For e.g., if a row had 8 4 2 2, move left would combine 2 and 2 to form 4 leading to 8 4 4 0. Now, it is

possible to combine further as the element to the left of 4 has the same value, thus after the second

combine, the row would be 8 8 0 0. And again 8 and 8 would form a 16. Thus the final values in the row

would be 16 0 0 0.

But if the row was 8 4 2 0 2, then moving left would result in 8 4 2 2 0. The cascading operation is allowed

only after a combination operation, There would no cascading operation if the element is swapped with 0.

Similar rules apply for move all right, wherein for every row elements starting from the leftmost position

move to their right.

You can either choose move all left or move all right operation but not both. Now given a state of the board,

you have determine what will be the maximum value on the board after either move all left or move all right.

Example

3

2 2 0

2 2 4

2 0 2

Move all left would result in:

4 0 0

4 0 4

2 2 0

The maximum value on the board after this move is 4.

Move all right would result in:

0 4 0

0 0 8

0 2 2

In the first row, 2 and 2 combines to form 4. In the second row, left most 2 combines with 2 to form 4. As the

element to its right has a value 4, combination operation cascades to form 8.

The maximum value on the board after this move is 8.

Now of the two operations, the higher of the two maximum values is 8. Thus the expected output is 8.

Input

3

2 2 0

2 2 4

2 0 2

Output

8

Input

3

0 0 4

0 2 2

0 4 8

Output

8

Time limit per test case:

1 second(s)

- 0of 0 votes
Suppose a 2D array of arbitary length is given. Any alphabet is given as input in the form of 0's and 1's with the 1's forming the alphabetical pattern. the topmost, leftmost, rightmost and the bottommost 1's form the border of the pattern. Find the topmost, bottom-most, left-most and the right-most 1 and hence find the dimensions of the margin of the pattern or its height and the width.

- 0of 0 votes
The problem is to write a set of functions to manage a variable number of byte queues, each with variable length, in a small, fixed amount of memory.

You should provide implementations of the following four functions:

// Creates a FIFO byte queue, returning a handle to it.

Q * create_queue();

// Destroy an earlier created byte queue.

void destroy_queue(Q * q);

// Adds a new byte to a queue.

void enqueue_byte(Q * q, unsigned char b);

// Pops the next byte off the FIFO queue

unsigned char dequeue_byte(Q * q);

So, the output from the following set of calls:`Q * q0 = create_queue(); enqueue_byte(q0, 0); enqueue_byte(q0, 1); Q * q1 = create_queue(); enqueue_byte(q1, 3); enqueue_byte(q0, 2); enqueue_byte(q1, 4); printf("%d", dequeue_byte(q0)); printf("%d\n", dequeue_byte(q0)); enqueue_byte(q0, 5); enqueue_byte(q1, 6); printf("%d", dequeue_byte(q0)); printf("%d\n", dequeue_byte(q0)); destroy_queue(q0); printf("%d", dequeue_byte(q1)); printf("%d", dequeue_byte(q1)); printf("%d\n", dequeue_byte(q1)); destroy_queue(q1);`

should be:

0 1

2 5

3 4 6

You can define the type Q to be whatever you want.

Your code is not allowed to call malloc() or other heap management routines. Instead, all storage (other than local variables in your functions) must be within a provided array:

unsigned char data[2048];

Memory efficiency is important. On average while your system is running, there will be about 15 queues with an average of 80 or so bytes in each queue. Your functions may be asked to create a larger number of queues with less bytes in each. Your functions may be asked to create a smaller number of queues with more bytes in each.

Execution speed is important. Worst-case performance when adding and removing bytes is more important than average-case performance.

If you are unable to satisfy a request due to lack of memory, your code should call a provided failure function, which will not return:

void on_out_of_memory();

If the caller makes an illegal request, like attempting to dequeue a byte from an empty queue, your code should call a provided failure function, which will not return:

void on_illegal_operation();

There may be spikes in the number of queues allocated, or in the size of an individual queue. Your code should not assume a maximum number of bytes in a queue (other than that imposed by the total amount of memory available, of course!)

You can assume that no more than 64 queues will be created at once.