Team Lead/ Tech Lead Interview Questions and Answers
Option D : Duplicate or Redundant Data.
Vankin’s Mile is an American solitaire game played on an n ? n square grid. The
player starts by placing a token on any square of the grid. Then on each turn, the player moves
the token either one square to the right or one square down. The game ends when player moves
the token o the edge of the board. Each square of the grid has a numerical value, which could be
positive, negative, or zero. The player starts with a score of zero; whenever the token lands on a
square, the player adds its value to his score. The object of the game is to score as many points
as possible. For example, given the grid below, the player can score 8 − 6 + 7 − 3 + 4 = 10 points
by placing the initial token on the in the second row, and then moving down, down, right, down,
down. (This is not the best possible score for this grid of numbers.)
(a) Describe and analyze an ecient algorithm to compute the maximum possible score for a game
of Vankin’s Mile, given the n × n array of values as input.
(b) In the European version of this game, appropriately called Vankin?s Kilometer, the player
can move the token either one square down, one square right, or one square left in each turn.
However, to prevent infinite scores, the token cannot land on the same square more than
once. Describe and analyze an ecient algorithm to compute the maximum possible score for
a game of Vankin’s Kilometer, given the n × n array of values as input.
str=’Have a nice day’
new_str=str.split(‘ ‘);
final_str=[]
for(let i = new_str.length-1;i>=0; i–){
final_str.push(new_str[i])
// console.log(i );
}
console.log(final_str.join(‘ ‘));
arr=[2,3,4,5]
for(let i =0; i<arr.length; i++){
for(let j =i+1; j<arr.length; j++){
if(arr[i]+arr[j]==8){
// console.log(arr[i],arr[j]);
temp=arr[i]
arr[i]=arr[j]
arr[j]=temp
}
}
}
console.log(arr)
x=153
y=x*2
arr=[]
for(i=x+1; i<y;i++){
temp=true
for(j=2; j<i;j++){
if(i%j==0){
temp=false
}
}
if(temp==true){
arr.push(i)
}
}
console.log(arr[0]);
111
To merge the two sorted halves of an integer array in place, you can use a modified version of the merge step in the merge sort algorithm. The idea is to start merging the two halves from the end of the array, so that there is no need for additional space.
Here’s a C++ implementation of the function:
cpp
Copy code
#include
void mergeSortedHalves(int arr[], int size) {
int i = (size / 2) – 1; // Last index of the first half
int j = size – 1; // Last index of the array
int k = size – 1; // Last index of the merged array
while (i >= 0 && j >= size / 2) {
if (arr[i] >= arr[j]) {
arr[k] = arr[i];
i–;
} else {
arr[k] = arr[j];
j–;
}
k–;
}
// Copy any remaining elements from the first half to the merged array
while (i >= 0) {
arr[k] = arr[i];
i–;
k–;
}
// The second half is already in its correct position
// Print the merged array
for (int m = 0; m < size; m++) {
std::cout << arr[m] << " ";
}
std::cout << std::endl;
}
int main() {
int arr[] = {1, 3, 6, 8, -5, -2, 3, 8};
int size = sizeof(arr) / sizeof(arr[0]);
mergeSortedHalves(arr, size);
return 0;
}
In this implementation, the mergeSortedHalves function takes an integer array arr and its size size as input. It assumes that the first half and second half of the array are already sorted.
The function initializes three pointers: i pointing to the last element of the first half, j pointing to the last element of the array, and k pointing to the last position of the merged array. It starts comparing elements from both halves and places the larger element at the position k in the merged array. The corresponding pointer is then decremented, and k is also decremented.
After merging the elements from the first half, the function copies any remaining elements from the first half to the merged array.
Finally, it prints the merged array.
Output:
diff
Copy code
-5 -2 1 3 3 6 8 8
#include
using namespace std;
int find(string needle, string haystack) {
int i, j;
for (i=0; i<haystack.size(); i++) { // i is my index for caterpillar
for (j=0; j<needle.size(); j++) { // j is my index for pill
if (i+j < haystack.size ()) {
if (haystack[i+j] != needle[j]) {
break;
}
}
}
return i;
}
return -1;
}
int main(){
cout << find("pill", "caterpillar") << endl;
}
If an online redo log file of a group is lost, the database remains in operation. … Oracle then uses the remaining member (or members) of this group to log the database changes.