Hot Topics

Texas Instrument Solution
Technical Round
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)
This approach has a time complexity of O(n) and a space complexity of O(1), making it an efficient solution for finding the missing number in the given 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';
This code reads a line of input into the input_string
variable and then copies the first 10 characters into the input
array, followed by a null terminator.
+------+ +------+
D --->| INV |----->| J |
+------+ +------+
In this diagram, the output of the inverter is connected to the J input of the JK flip-flop. The K input of the JK flip-flop is connected to VCC (logic 1).
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
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.
#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");
printf("\nEnter your choice");
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]);
}
}
}




Popular Category
Hot Topics
Go through our study material. Your Job is awaiting.