Posts

Showing posts with the label 2022-reviewed

Find the shorted path from the vertex 0 for given list of vertices.

Question For input (separated by a tab) from this link , compute the shortest path from a vertex, 0 to the following vertices. The file contains an adjacency list representation of an undirected weighted graph with 200 vertices labeled 1 to 200.  Each row consists of the node tuples that are adjacent to that particular vertex along with the length of that edge. For example, the 6th row has 6 as the first entry indicating that this row corresponds to the vertex labeled 6. The next entry of this row "141,8200" indicates that there is an edge between vertex 6 and vertex 141 that has a length of 8200.  The rest of the pairs of this row indicate the other vertices adjacent to vertex 6 and the lengths of the corresponding edges. Report the shortest path in the same order of given vertices vertices = [7,37,59,82,99,115,133,165,188,197] if you find that all ten of these vertices except 115 are at a distance of 1000 away from vertex 1 and 115 is 2000 distances away, then your answer s...

Finding possible permutation of N words [reviewed]

Problem Permutate a list of string  this question is supposed to permutate the characters instead of the whole string,  Here is input example {"red", "fox", "super" } the expected output is  r fs, rfu, rfp, rfe, rfr, ros, rou, rop, roe, ror, rxs, rxu, rxp, rxe, rxr, efs, efu, efp, efe, efr, eos, eou, eop, eoe, eor, exs, exu, exp, exe, exr, dfs, dfu, dfp, dfe, dfr, dos, dou, dop, doe, dor, dxs, dxu, dxp, dxe, dxr

Managing the conference rooms with balancing the occupancy percentage

Problem Given the list of conference rooms with the capacity and the target occupancy percentages, write the program that maintains the balanced occupancy percentage across the rooms. Input: list of rooms { [30, 0.6], [50, 0.7], [90, 0.4]}, number of guests Output: list of rooms with balanced occupancy percentages across the rooms

Reordering the values in the binary tree.

Problem Given the tree as below, write the code that fixes the order of the tree such that the value of the parent is always larger than the value of the children (left, right) struct node {     int value;     node *left;     node *right;     node(int v):value(v),right(0),left(0){) } Input: root node                2             /    \            5       10           / \     /  \          4   3   8    9                    / \      /  \                 12  6  1   11 The expected result will be:            12       ...

Decoding numeric string to alphabets.

Image
Problem Given a string of integers returns the number of ways to decode integers back to Alphabets using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 examples: input = 199 output = 2 explanation: 1-> 9 -> 9 (AII) 11-> 9 (KI) input = 11 output = 1 explanation: 1->1 (AA) 11 (K)

Finding the shortest path from start to end word given list of words

Given list of array and start and end word as below:    ["hot", "hit", "his", "hat"] Start word: "hot" End word: "his" Find the shortest sequence starting the from start and ending the with end word. The rule is, from the start word, each time you can only change one character, and only use words from the given set, find out how to get to the end word. In the above example, the sequence is:    hot  -> hit -> his (hat is not used) for this example: start = 'his' end = 'hit' input = ["his", "has", "hit", "hat"] we can find this: his -> has -> hat -> hit. However: his -> hit is the sorted path.

Checking whether interval (a,b) is covered given 1-D list of coordinates

Question Given 1-D list of co-ordinates determine if interval (a,b) is covered Ex - [(2,5), (5,7),(1,4)] and interval = (1,6) return true Explanation - Points 1 to 6 lies in list of interval given 1 to 4. 2 to 5 and 5 to 7. [(1,4),(6,7),(2,5)] and interval - (1,6) return false Explanation - Distance between 5 to 6 is not covered in the list given so return false

Write serialize and deserialize functions for an array of strings

Problem Write 2 functions to serialize and deserialize an array of strings. strings can contain any Unicode character. Do not worry about string overflow. input = ['abdcd', '4agasd-dsfafdas', 'hi there I love you'] output = serialize(input) deserialize(output) = ['abdcd', '4agasd-dsfafdas', 'hi there I love you']

Given two strings, write a method to decide if one is a permutation of the other

Problem Given two strings, write a method to decide if one is a permutation of the other. Example)  Given two strings, "mom", "grandmom", your algorithm should return True because "mom" is the permutation of "grandmom".

Finding the element in the M X N matrix sorted in ascending order

Problem Given an M $\times$ N matrix in which each row and each column are sorted in ascending order, write a method to find an element.

Finding the string in the sorted array of strings with empty strings

Problem Given a sorted array of strings that is interspersed with empty strings, write a method to find the location of a given string. Example input: find "ball" in  {"at", "", "", "","ball", "", "", "car", "", "". "dad", "",""} Output: 4

Merge two sorted array A and B, where A has larger buffer to hold B at the end of it.

Problem You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B. Write the algorithm to merge A and B without allocation additional memory.

Evaluating the mathmatic expression with parentheses

Image
Problem Given arithmetic equation, 2+(3-1)*4/(5-6), write the program to calculate the result of the equation.

Write a method to compute all permutations of a string

Problem Write a method to compute all permutations of a string For example: given an input string, "abc", your program should print the following permutations: a ab abc ac acb b ba bac bc bca c ca cab cb cba

Finding the magic index in array, A

Image
Problem A magic index in an array A [0. . .n-1] is defined to be an index such that A[i] = i. Given a sorted array of distinct integers, write a method to find a magic index, if one exists, in array A. FOLLOW UP What if the values are not distinct?

Find the ways of climb up the stairs

Problem A child is running up a staircase with n steps, and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the a child can run up the stairs.

Planting flowers with no adjacent flower plots

Image
Problem Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die. Given a flowerbed (represented as an array containing booleans), return if a given number of new flowers can be planted in it without violating the no-adjacent-flowers rule  Sample inputs  Input: 1,0,0,0,0,0,1,0,0  3 => true  4 => false  Input: 1,0,0,1,0,0,1,0,0  1 => true  2 => false  input: 0  1 => true  2 => false  public boolean canPlaceFlowers(List flowerbed, int numberToPlace) {  // Implementation here  }

Moving zeros in the array to the left

Image
Problem  Push all the zero's of a given array to the end of the array. In place only. Ex 1 , 2 , 0 , 4 , 0 , 0 , 8 becomes 1 , 2 , 4 , 8 , 0 , 0 , 0. No additional allocation of array is not allowed. Everything should happen in place.

Mapping the donut orders

Problem [reviewed on 2022/03/27] You are given the two array of strings: dountType: the first one is donut name and the second one is donut type [ [ "crullar", "vegan"], [ "beignet", "coffee"] ] order: the first one is the name of the people and the second one is donut type. [ [ "jose" , "vegan"], [ "john", "coffee"] ] You need to write the program listing the following output. [   ["john", "beignet"], ["jose", "cruller"] ] Each person can like either one donut for all donuts. If a person like all donuts, the input will be like below: ["Adam", "*"] In that case, the output should be [ "Adam", "beignet"], ["Adam", "crulller"] Note the output is sorted primarily by the name and secondarily by the donut name. You need to implement the following method: # c++ vector < vector < s...

Merging partially sorted arrays into one array

Problem   Given three arrays of integers, each of which is sorted, write the program that merges three arrays into one keeping the integers sorted.  Example inputs:   arr1  = { 3 , 7 , 9 , 15 , 35 };   arr2  = { 2 , 8 , 45 , 60 , 70 , 100 };   arr3  = { 5 , 6 , 50 , 101 ,  110 };