# Linkedin Overall Interview Questions + Coding Solutions- codewindow.in #### Describe a routine which returns the set of integers in {1..100} divisible without remainder by 3 but not by 9.

##### One possible routine to accomplish this task is to use a loop to iterate through the numbers in the range {1..100}, and use an if statement to check if each number is divisible by 3 but not by 9. Here's an example in Python:
``````def divisible_by_3_not_9(numbers):
result = set()
for num in numbers:
if num % 3 == 0 and num % 9 != 0:
return result

numbers = range(1, 101)
result = divisible_by_3_not_9(numbers)
print(result)``````

#### Find median of an infinite stream of integers in O(1) time.

##### Here's an example implementation in Python:
``````import heapq

class MedianHeap:
def __init__(self):
self.max_heap = []
self.min_heap = []

if len(self.max_heap) == 0 or element <= -self.max_heap:
heapq.heappush(self.max_heap, -element)
else:
heapq.heappush(self.min_heap, element)
if len(self.max_heap) > len(self.min_heap) + 1:
heapq.heappush(self.min_heap, -heapq.heappop(self.max_heap))
elif len(self.min_heap) > len(self.max_heap):
heapq.heappush(self.max_heap, -heapq.heappop(self.min_heap))

def get_median(self):
if len(self.max_heap) == len(self.min_heap):
return (-self.max_heap + self.min_heap) / 2
else:
return -self.max_heap

median_heap = MedianHeap()

median = median_heap.get_median()
print(median)
/*
Output: 2.5
*/
``````

#### Write a function that, given a list of integers (both positive and negative) returns the sum of the contiguous subsequence with maximum sum. Thus, given the sequence (1, 2, -4, 1, 3, -2, 3, -1) it should return 5.

##### Here's an implementation in Python:
``````def max_sum_contiguous_subsequence(numbers):
max_sum = float("-inf")
current_sum = 0
for num in numbers:
current_sum = max(current_sum + num, num)
max_sum = max(max_sum, current_sum)
return max_sum

numbers = [1, 2, -4, 1, 3, -2, 3, -1]
result = max_sum_contiguous_subsequence(numbers)
print(result)
/*
OUTPUT 5
*/``````

#### Search a sorted array for the first element larger than k.

##### Here's an implementation in Python:
``````def search_first_larger_than(numbers, k):
left, right = 0, len(numbers) - 1
while left <= right:
mid = (left + right) // 2
if numbers[mid] <= k:
left = mid + 1
else:
right = mid - 1
return left if left < len(numbers) else -1

numbers = [1, 2, 3, 4, 5, 6, 7]
result = search_first_larger_than(numbers, 4)
print(result)
/*
OUTPUT _ - 5
*/``````

#### Print binary tree level by level.

##### Here's an implementation in Python using a tree node class:
``````class TreeNode:
def __init__(self, val=None, left=None, right=None):
self.val = val
self.left = left
self.right = right

def print_level_by_level(root):
if root is None:
return
queue = [root]
while queue:
level_size = len(queue)
for i in range(level_size):
current = queue.pop(0)
print(current.val, end=" ")
if current.left:
queue.append(current.left)
if current.right:
queue.append(current.right)
print()

root = TreeNode(1)
root.left = TreeNode(2)
root.right = TreeNode(3)
root.left.left = TreeNode(4)
root.left.right = TreeNode(5)
root.right.left = TreeNode(6)
root.right.right = TreeNode(7)
print_level_by_level(root)
/*
1
2 3
4 5 6 7
*/``````

#### Find distance between words in a string e.g.: String => "I am a good girl" distance between "I" and "good" is 3.

##### Here's an implementation in Python:
``````def word_distance(sentence, word1, word2):
words = sentence.split()
idx1, idx2 = -1, -1
min_distance = float("inf")
for i, word in enumerate(words):
if word == word1:
idx1 = i
if idx2 != -1:
min_distance = min(min_distance, idx1 - idx2)
if word == word2:
idx2 = i
if idx1 != -1:
min_distance = min(min_distance, idx2 - idx1)
return min_distance

sentence = "I am a good girl"
result = word_distance(sentence, "I", "good")
print(result)
/*
OUTPUT - 3
*/
``````

#### Given a nested list of integers, returns the sum of all integers in the list weighted by their depth  given the list {{1,1},2,{1,1}} the function should return 10 (four 1's at depth 2, one 2 at depth 1).

##### Here's a function in Python that computes the sum of all integers in a nested list of integers weighted by their depth:
``````def nested_list_sum(lst, depth=1):
total = 0
for element in lst:
if type(element) is int:
total += element * depth
elif type(element) is list:
total += nested_list_sum(element, depth + 1)

#### Write a function and return true or false if there is a pair of number that sum up as 10

##### Here's a function in Python that returns `True` if there is a pair of numbers in a list that sum up to 10:
``````def has_pair_with_sum(lst, target_sum):
seen = set()
for num in lst:
if target_sum - num in seen:
return True
return False``````

#### How to check if the string is palindrome?

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

int main()
{
char str;
int flag;

printf("Enter a string");
gets(str);

int len=strlen(str);

for(int i=0;i<len/2;i++){
if(str[i]==str[len-i-1])
flag=0;
}

if(flag){
printf("String is not palindrome");
}
else{
printf("String is palindrome");
}
return 0;
}
/*
OUTPUT -
Enter a string
121
String is palindrome
*/``````

#### Write a function that takes a string and check if it is a number

##### Here's a function in Python that checks if a string is a number:
``````def is_number(string):
try:
float(string)
return True
except ValueError:
return False``````

#### Write a function that takes a string and check if it is a number

##### Here's a function in C++ that finds a number in a sorted array that has been rotated:
``````#include <iostream>

using namespace std;

bool findNumber(int numbers[], int n, int target) {
int left = 0;
int right = n - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (numbers[mid] == target) {
return true;
} else if (numbers[left] <= numbers[mid]) {
if (numbers[left] <= target && target < numbers[mid]) {
right = mid - 1;
} else {
left = mid + 1;
}
} else {
if (numbers[mid] < target && target <= numbers[right]) {
left = mid + 1;
} else {
right = mid - 1;
}
}
}
return false;
}

int main() {
int numbers[] = {6,7,1,2,3,4,5};
int n = sizeof(numbers) / sizeof(numbers);
int target = 3;
if (findNumber(numbers, n, target)) {
cout << "The target number is found in the array." << endl;
} else {
cout << "The target number is not found in the array." << endl;
}
return 0;
}
/*
OUTPUT - The target number is found in the array.
*/
``````
##### This function uses the `float` function to try converting the string to a floating-point number. If the conversion succeeds, the function returns `True`, indicating that the string is a number. If the conversion fails, a `ValueError` is raised, and the function returns `False`, indicating that the string is not a number. Note that this function only checks for floating-point numbers and not for other types of numbers such as integers or complex numbers. #### Nagarro Solved  #### Automata Fixing  ## We Loveto Support you

Go through our study material. Your Job is awaiting.