# Texas Instrument Interview Questions + Coding Solutions – codewindow.in

## Texas Instrument Solution

#### Given an array of 999 numbers with each number being unique and in the range of 1-1000. What is the most optimum way to find the missing number?

##### One approach to finding the missing number in the given array is to use the mathematical formula for the sum of an arithmetic series, which is (minimum number + maximum number) * (number of terms) / 2, and compare it to the sum of the numbers in the array. The missing number will be the difference between the expected sum and the actual sum. Here's an example in Python:
``````def find_missing_number(arr):
n = len(arr)
expected_sum = (1 + 1000) * 1000 // 2
actual_sum = sum(arr)
return expected_sum - actual_sum

arr = [1, 2, 3, ..., 999]
missing_number = find_missing_number(arr)
print("The missing number is:", missing_number)
``````

#### What is the problem with the following code? char[10] input; cin >> input;

##### To solve these problems, you can use the `getline` function to read input into a string and then copy the first 10 characters into the `input` array:
``````char input[11];
string input_string;
getline(cin, input_string);

int length = min(10, (int)input_string.length());
for (int i = 0; i < length; i++) {
input[i] = input_string[i];
}
input[length] = '\0';
``````

#### Conversion of d flip-flop to jk flip-flop.

##### A D flip-flop can be converted to a JK flip-flop by adding an inverter to the inputs. A JK flip-flop is a type of flip-flop that has two inputs, J and K, that can be used to set, reset, or toggle the output.
``````      +------+      +------+
D --->| INV  |----->| J    |
+------+      +------+
``````
##### The truth table for this conversion is as follows:
``````D | Q(t) | J | K | Q(t+1)
-----------------------------
0 |   0  | 1 | 0 |    1
0 |   1  | 1 | 0 |    0
1 |   0  | 0 | 1 |    1
1 |   1  | 0 | 1 |    0
``````

#### How do you find the distance between two nodes in a Binary Tree?

##### Here's an example of the algorithm in action:
``````Given the following binary tree:

Tree:
20
/  \
10    30
/ \   /  \
5  15 25   35

Suppose you want to find the distance between the nodes with values 15 and 35. The LCA of these nodes is 20, and the depths of the two nodes are 3 and 4, respectively. The distance between the nodes is 3 + 4 = 7.
``````

#### Implement Stack in C language.

``````#include <stdio.h>
#include <stdlib.h>
#define MAX 5
//Structure Declaration
typedef struct st_array{
int a[MAX];
int top;
}stack;

void push(stack *p,int n);
void pop(stack *p);
void display(stack* p);

int main(void) {
int ch,val;
stack s;
s.top = -1;

while(1){
printf("\n1.Push\n2.Pop\n3.Display\n4.Exit");
scanf("%d",&ch);

switch(ch){
case 1:printf("Enter the value");
scanf("%d",&val);
push(&s,val);
break;

case 2:printf("Deleting the top");
pop(&s);
break;

case 3:printf("Display");
display(&s);
break;

case 4:exit(0);
default:printf("\nWrong Input");
}

}
return 0;
}

void push(stack *p,int n){
if(p->top == MAX-1){
printf("Stack is full");
}
else{
p->top++;
p->a[p->top]=n;
printf("Successfully Inserted");
}
}

void pop(stack *p){
int x;
if(p->top == -1){
printf("Stack is Empty");
}
else{
x=p->a[p->top];
p->top--;
printf("%d is deleted",x);
}
}

void display(stack *p){
int i;
if(p->top == -1){
printf("Stack is empty");
}
else{
for(i=p->top;i>=0;i--){
printf("%d\t",p->a[i]);
}
}
}``````

## We Loveto Support you

Go through our study material. Your Job is awaiting.