## C Interview Questions

- 0of 0 votes
Fill the arrow with zeros in n*n matrix.{{0,0,0,0,0,0,0

0,0,1,1,1,0,0

0,0,1,0,1,0,0

0,0,1,0,1,0,0

0,1,0,0,0,1,0

0,0,1,0,1,0,0

0,0,0,1,0,0,0}}

- 0of 0 votes
Given an integer n, replace its bits starting from the bit at position a to the bit at position b, inclusive, with the bits of integer k. Count from the least significant bit to the most significant bit, starting from 0.

Example:

For n = 1024, a = 1, b = 6 and k = 17, the output should be

insertBits(n, a, b, k) = 1058.

n = 100 0000 00002, k = 1 00012, 1058 = 100 0010 00102.

For n = 11, a = 1, b = 2 and k = 2, the output should be

insertBits(n, a, b, k) = 13.

n = 10112, k = 102, 13 = 11012.

- 0of 0 votes
Given a math expression in string format that contains only + & - and numbers. Return the sum in integer format. Eg: Input: "3+4-7+13" Output: 13.

"2+1-8+13" Output: 8

- 0of 0 votes
Implement a function that takes two strings, s and x, as arguments and finds the first occurrence of the string x in s. The function should return an integer indicating the index in s of the first occurrence of x. If there are no occurrences of x in s, return -1.

Example:

For s = "AGoogleInterviewIsAwesome" and x = "IA", the output should be

strstr(s, x) = -1;

For s = "AGoogleIsAwesome" and x = "IsA", the output should be

strstr(s, x) = 10.

Apparently, my solution was not efficient enough with string lengths that are 2000+:`int findFirstSubstringOccurrence(String s, String x) { int sLen = s.length(); int xLen = x.length(); int tracker = 0; if (sLen == xLen) { if (s.equals(x)) { return 0; } else { return -1; } } else { if (xLen >= 1) { for (int index = 0; index < sLen; index++) { if (s.charAt(index) == x.charAt(tracker)) { tracker++; if (tracker == xLen) { return index - (xLen - 1); } } else { index -= tracker; tracker = 0; } } } } return -1; }`

- 0of 0 votes
An n * m matrix represents an array of computers, giving you a List <int []> that represents the coordinates of the broken computer.

Now we start from (0,0) repair computer requirements:

1. You must finish all the broken computers in the current line to get to the next line

2. To go to the next line, the mechanic must first return to the far left or right of this line

And then find repair each computer order that has the minimum access distance,

- 0of 0 votes
Assume there is no software like google maps. you are given a map of world. Suppose you are somewhere in the hyderabad.

You will have to figure out all the paths from your location to Hyderabad airport.

I have given DFS approach. But the problem is that by doing DFS, a path can cross boundaries of Hyderabad and go so long away from Hyderabad

airport. DFS will take some much time. How to solve this problem?

You are give very big file (15TB) of employees sign in and sign out data. The file contains information like below

EmployeeId,Date,SignIn Time,SignOut TIme

An Employee can sign in and sign out multiple times in a single day.

Question: Given EmployeeId, day and time, your algorithm has to tell whether employee is present in the office or not at that particular time

- 0of 0 votes
Assume there is no software like google maps. you are given a map of world. Suppose you are somewhere in the hyderabad.

You will have to figure out all the paths from your location to Hyderabad airport.

I have given DFS approach. But the problem is that by doing DFS, a path can cross boundaries of Hyderabad and go so long away from Hyderabad

airport. DFS will take some much time. How to solve this problem?

- 0of 0 votes
A robot can only be moved one step to the right (x + 1) at a time while moving upward or downward or horizontally (y-1, y + 1, y) , given the starting and ending positions, and a series of points must pass, ask how many kinds of ways from start to end.

- 0of 0 votes
"""

Given a 2d array of 0s and 1s, 0 means water,

1 means land, connected 1s form an island,

count the number of islands on this map.

01010

01001

01101

returns 3

"""

- 0of 0 votes
# Given a dictionary, find all pairs of words that,

# when concatenated together, form a palindrome.

# â€˜none', 'xenon': 'nonexenon' is a palindrome

# 'none', 'xexenon': 'nonexexenon' is a palindrome

- 0of 0 votes
Find if the shorter string is a subsequence of the longer string

Output the second index corresponding to the first one, requiring output only If there is only one match, and false if there is more than one pair

a b c d e f g, a b -> [0,1]

a b b c, ab c -> False

- 0of 0 votes
To several bus lines, each line is a two-way line, such as:

0: A <-> B <-> D

1: C <-> D

give you a start and end, find the path through the least station. followup

Asked the least transfer case

- 0of 0 votes
Thanks for the suggestions I was trying to answer this question: Write a program that takes as input a string of only letters and displays the string with every third letter capitalized starting with the second letter, and all other letters lower-case.

What is optimal implementation

Question is also Describer here:

https://stackoverflow.com/questions/9713205/string-manipulation-java

- 0of 0 votes
How would you work with a backend engineer to design a news feed on mobile. Imagine that we only care about showing the user feed and posting a picture.

Follow-ups

1. what kind of apis would you want him to expose and what would they look like

2. How would you refresh the news feed on the iOS app and how often?

3. How would you cache the data/images. What size cache would you have?

- 0of 0 votes
Design a data structure which reads below block of text

*Status update1

**Joe is working on a bug

**Alice is on vacation

*StatusUpdate2

**Alex finished task1

and returns me an Object such that I can navigate the this nested text easily like this:

obj.children[0] - > returns "StatusUpdate"

obj.children[0].children[1] -> "Alice is on vacation"

- 0of 0 votes
Given a Tree where each node contains an attribute say color(R,G,B... etc). find subtree with maximum number of attributes.

Input:

G

/ \

B R

/ \ / \

B B R R

/ \ / \

B R R R

Output:

Input:

R

/ \

R R

\ / \

R R R

- 2of 2 votes
Convert a string with digits into a literal representation of the number like: 1001 to one thousand one

- 0of 0 votes
Determine whether the inorder of n binary trees is the same

- 0of 0 votes
Give you a csv file There are three columns are id, parent, weight Then give you a class Node which has these three fields

But you also have the option of adding more fields for you to print out all the node's subwebs.

The definition of subweight is the sum of the node's weight plus the subweight of his children.

- 0of 0 votes
Give a chessboard, check if a group of white chesses are surrounded by all black chesses.

- 0of 0 votes
`We encode a string, s, by performing the following sequence of actions: Replace each character with its ASCII value representation. Reverse the string. For example, the table below shows the conversion from the string "Go VMWare" to the ASCII string "711113286778797114101": // Character G o V M W a r e // ASCII Value 71 111 32 86 77 87 97 114 101 // // We then reverse the ASCII string to get the encoded string 101411797877682311117. // // For reference, the characters in s are ASCII characters within the range 10 - 126 which include special characters. // // Complete the decode function in the editor below. It has one parameter: // encoded - A reversed ASCII string denoting an encoded string s. // // The function must decode the encoded string and return the list of ways in which s can be decoded. static Collection<String> decode(String encoded) { }`

- 1of 1 vote
Imagine a computer where you have no "/" (divide) operation. All other operations are implemented including addition, multiplication, binary shift etc. Implement function div(int a, int b) using available operators only.

- 2of 2 votes
Given the list of the numbers. In this list, there are the numbers from the Fibonacci sequence.

Write the algorithm that retrieves all the numbers which belong to the Fibonacci sequence of numbers.

- 0of 0 votes
Given a list of relationship of report

A reported to D, D reported to Z, who are reported to Z

- 0of 0 votes
Give the structure of a directed graph

START -> a -> b -> c -> END

If a word can start from start and end at END, then we think the word is in this diagram

For example, the string "abc" is consistent, but "ab" does not match,

Although "ab" is also inside the graph, b's next is "c" instead of END, so it's not legal word

(Note: each node can have more than one next)

1. According to the problem, design the data structure

Write a function, input is START and a string, to determine whether the string is a valid word

3. follow up, if the graph has cycle, how to do?

4. If the graph has repeated characters how to do?

- 0of 0 votes
Javascript solution for this question???

Given a list of characters, write a function to output a list of length of minimum non overlapping subsequences that can partition the input list.

For example:

Input : [a,b,c]

Output: [1,1,1]

Explanation: There are no repeated characters.

Input : [a,b,c,a]

Output: [4]

Explanation: The 'a' is repeated so one subsequence is between a to last a.

Input : [a,b,c,b,a,e,b,a,d,f,g,d,f,i,f,k,l,m,n,m,l]

Output: [8,7,6]

Explanation: max length from 1st 'a' to last 'a' is 8.

1st 'f' to last is 6 adding d to it = 7

so on

- 2of 2 votes
Decompress string - string (s) followed by {n} denotes s repeating n times

"a(b(c){2}){2}d" decompresses to "abccbccd"

"((x){3}(y){2}z){2}" decompresses to "xxxyyzxxxyyz"

- 0of 0 votes
Design a system that works like the you see on Amazon search - lets say you enter 'women's sandals'. What happens in the background? Explain all that you can think of.

- 0of 0 votes
what is JAVASCRIPT Solution for this questions:

Michelle has created a word game for her students. The word game begins with Michelle writing a string and a number, K, on the board.

The students must find a substring of size K such that there is exactly one character that is repeated one;

in other words, there should be k - 1 distinct characters in the substring.

Write an algorithm to help the students find the correct answer. If no such substring can be found, return an empty list;

if multiple such substrings exist, return all them, without repetitions. The order in which the substrings are does not matter.

Input:

The input to the function/method consists of two arguments - inputString, representing the string written by the teacher;

num an integer representing the number, K, written by the teacher on the board.

Output:

Return a list of all substrings of inputString with K characters, that have k-1 distinct character i.e.

exactly one character is repeated, or an empty list if no such substring exist in inputString.

The order in which the substrings are returned does not matter.

Constraints:

The input integer can only be greater than or equal to 0 and less than or equal to 26 (0 <= num <= 26)

The input string consists of only lowercase alphabetic characters.

Example

Input:

inputString = awaglk

num = 4

Output:

[awag]

Explanation:

The substrings are {awag, wagl, aglk}

The answer is 'awag' as it has 3 distinct characters in a string of size 4, and only one character is repeated twice.

- 0of 0 votes
Given a Binary string of 0s and 1s, and k, Find the number of different ways to get longest continuous streak of 1s. You can flip any k number of 0s to 1s.

Example:

1)Stirng is S=1010101, K=1

Result=3

1)Stirng is S=01010, K=3

Result=1