NIC
BAN USER- 1of 1 vote
Answersboolean checkPattern(String str)
- NIC in India
{
// Implementation
}
Implement the method checkPattern. str is a string argument.
Return true: if the string is following any pattern
example: xyzxyzxyz
Here "xyz" is the pattern
return false: String is not following pattern
example: xyzxyzA
A is not in part of pattern.| Report Duplicate | Flag | PURGE
Interra System Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven an array arr=[5,2,-3,4,1]
- NIC in United States
print
_ _ * * * * *
_ _ * *
* * *
_ _ * * * *
_ _ *
Note [In real question, replace _ by blank(or space)]. So, while solving this question need to replace _ by blank ].| Report Duplicate | Flag | PURGE
Intelligrape Java Developer Algorithm - 0of 0 votes
AnswersGiven two classes C1 and C2 which are almost same.(remember not exactly same).
- NIC in India
You want to choose best among these classes so that it can be use as key in hashmap.
What question will you ask regarding two classes C1 and C2.| Report Duplicate | Flag | PURGE
makemytrip Software Engineer / Developer Java - 0of 0 votes
AnswersGiven a binary tree and a range as min and max.
- NIC in United States
Modify the tree such that number formed by traversing tree from root to leaf all fall in given range.
1
2 3
4 5 6 7
let say range is 125 - 136
Modified tree
1
2 3
null 5 6 null| Report Duplicate | Flag | PURGE
Josh Software Engineer / Developer Algorithm - 3of 3 votes
AnswersGiven a sorted array. Now following operations may be applied on even position elements:
- NIC in India
swap elements on even position. An element may be swap only once.
eg. 1 2 3 4 5 6 7 8 9 10
modified array:
1 2 3 8 5 10 7 4 9 6.
Find any given element in less than o(n) complexity.| Report Duplicate | Flag | PURGE
Josh Software Engineer / Developer Algorithm - 1of 1 vote
AnswersTo find loop in a circular linked list, we generally move two pointers , one with speed of one move at a time and other at two at moves at a time. Why do we use ratio 2:1. What can be the best ratio of speed to find a loop in linked list
- NIC in India| Report Duplicate | Flag | PURGE
Adobe Member Technical Staff Problem Solving - 1of 1 vote
AnswersGiven N,find all a and b combination which satisfies a^3 + b^3 = N
- NIC in India| Report Duplicate | Flag | PURGE
Adobe Member Technical Staff Algorithm - 0of 0 votes
AnswersYou are given a tree (a simple connected graph with no cycles).You have to remove as many edges from the tree as possible to obtain a forest with the condition that : Each connected component of the forest contains even number of vertices
- NIC in United States
Your task is to calculate the number of removed edges in such a forest.| Report Duplicate | Flag | PURGE
Algorithm
private static String addInRange(String s, int start,int end)
{
if(start<=end)
return s.substring(start,end);
return "";
}
public static void printSeq(String str, Map<Character, List<Character>> map)
{
System.out.println(str);
int length = str.length();
StringBuffer sb ;
for(int i=0;i<length;i++)
{
sb = new StringBuffer();
char cLetter = str.charAt(i);
List<Character> list = map.get(cLetter);
sb.append(addInRange(str,0,i));
for(Character chr:list)
{
StringBuffer newSb = new StringBuffer();
newSb.append(sb);
newSb .append(chr);
newSb.append(addInRange(str,i+1,length));
System.out.println(newSb.toString());
}
}
}
We have two array : A1 and A2.
1. Calculate size of A1 and A2. //O(n)
2. Insert smaller array in hashMap //O(n)
Map<Character,Boolean> map = new HashMap<Character,Boolean>();
for(int i=0;i<A1.length;i++)
{
map.put(A1[i],false);
}
3. Now traverse second array(bigger one) ans set true in map for values present in A
for(int i=0; i<A2.length;i++) //O(n)
{
if(map.contains(A2[i]))
{
map.put(A2[i],true);
}
}
4. for(Character c:map.keySet()) //0(n)
{
if(!map.get(c))
{
System.out.print(c);
}
}
Overall complexity: Time : O(n)
Space: O(n)
It will begin and ends with same pattern
- NIC January 03, 2015For xyz it will be: xyzxyz. In terms of regular expression : (xyz)*