Green
BAN USERLove to Solve the Unsolved...
- 0of 0 votes
AnswersGiven three strings a, b, c. Write a function to find the smallest subsequence in a, which contains all the characters from b but none from c.
- Green in India for Machine coding
* b and c are mutually exclusive.| Report Duplicate | Flag | PURGE
Flipkart Java Developer Coding - 0of 0 votes
AnswersCreate a Employee Database for an organization. Each employee may or may not have a manager. One employee may have many subordinates. This can grow upto any level.
- Green in India for Machine coding
* Find all the subordinates for a given employee.
* Find the manager details of an employee.
Assumptions:
* Employee contains
ID: int (Unique)
Name: string
Designation: string
Email: string
* One employee can have only one manager.
* All the information is in-memory. No database needed.| Report Duplicate | Flag | PURGE
Flipkart Java Developer Coding
This is a kind of sudo-code.
- find the start char of the pattern
- change the head pointer to that node
- Iterate the LL
- Mark the start of a pattern
- iterate the LL till all characters from the pattern are organized in a section
- move the start pointer to the next item of the end of the 1st section
- continue till the start pointer.next is actually the head of the LL
p = pattern[];
find the first char of the pattern in the LL,
say, a points to the node containing the 1st char of the pattern
while(a.next != head){
b = a;
c = b.next;
foreach(char in p){
if(p[i] == b.val){
b = c;
c = c.next;
} else {
while(c.val != p[i])
c = c.next;
swapNodes(b,c);
}
}
a = c;
}
The simple merge of every 2 arrays should be easier:
import java.util.ArrayList;
import java.util.List;
/**
* @author Sabuj
*
*/
public class Merge {
public static void main(String[] args) {
List<Integer[]> arrays = new ArrayList<Integer[]>();
arrays.add(new Integer[]{10, 15, 17, 20});
arrays.add(new Integer[]{5, 7, 11, 19, 22});
arrays.add(new Integer[]{1, 8, 12});
Integer[] p = mergeArrays(arrays);
for (int i = 0; i < p.length; i++) {
System.out.print(p[i] + ", ");
}
}
public static Integer[] mergeArrays(List<Integer[]> arrays){
if(arrays == null || arrays.size() == 0)
return null;
Integer[] p, q;
if(arrays.size() >= 2){
p = arrays.get(0);
for (int i = 1; i < arrays.size(); i++) {
p = merge(p, arrays.get(i));
}
} else {
return arrays.get(0);
}
return p;
}
public static Integer[] merge(Integer[] a, Integer[] b){
Integer[] c = new Integer[a.length+b.length];
int i=0, j=0, k=0;
while(i < a.length && j < b.length){
if(a[i] <= b[j])
c[k++] = a[i++];
else
c[k++] = b[j++];
}
while(i < a.length)
c[k++] = a[i++];
while(j < b.length)
c[k++] = b[j++];
return c;
}
}
O/P:
- Green April 29, 2014