jayram singh
BAN USER- 0of 2 votes
AnswersGiven an array A of integers, find an integer k that is not present in A. Assume that the integers are 32-bit signed integers.
- jayram singh in United States| Report Duplicate | Flag | PURGE
- 6 Answers programming twist
You have N soldiers numbered from 1 to N. Each of your soldiers is either a liar or a truthful person. You have M sets of information about them.Each line contains 3 integers - A, B and C. This means that in the set of soldiers numbered as {A, A+1, A+2, ..., B}, exactly C of them are liars.
- jayram singh October 09, 2012
There are M lines like the above.
Let L be the total number of your liar soldiers. Since you can't find the exact value of L, you want to find the minimum and maximum value of L.
The first line of the input contains two integers N and M.
Each of next M lines contains three integers - A, B and C (1 <= Ai <= Bi <= n) and (0 <= Ci <= Bi-Ai). where Ai, B i and C i refers to the values of A, B and C in the ith line respectively
N and M are not more than 101, and it is guaranteed the given informations are satisfiable. You can always find a situation that satisfies the given information .
Print two integers Lmin and Lmax to the output.| Flag | PURGE
Add a comment when someone vote it down
- jayram singh June 19, 2013Test Cases: Check for
- NULL string
- "" empty string
- "a" string that consists only one word
- More than one space between words
Stupid question...and same the answers...How can you check if an array is circular??
The question is asking for a queue using an array and you all implement it using linked list, why?
Shall we consider the root as one of the extremes ...if yes then left extreme or right extreme?
- jayram singh June 09, 2013These are common problems with the multi-threaded programming
1. Race condition
2. DeadLock
3. LiveLock
4. Priority Inversion
5. Two-Step Dances
6. Lock Convoys
1) Reverse the whole string from start to end and you get the this output.
"remmargorp erawtfos a ma I"
2) Reverse the individual words at odd locations, we get the below string.
"programmer erawtfos a ma I"
You can use the java.lang.instrumentation package:
docs.oracle.com/javase/7/docs/api/java/lang/instrument/Instrumentation.html
It has a method that can be used to get the implementation specific approximation of object size, as well as overhead associated with the object.
import java.lang.instrument.Instrumentation;
public class ObjectSizeFetcher {
private static Instrumentation instrumentation;
public static void premain(String args, Instrumentation inst) {
instrumentation = inst;
}
public static long getObjectSize(Object o) {
return instrumentation.getObjectSize(o);
}
}
Use getObjectSize:
public class C {
private int x;
private int y;
public static void main(String [] args) {
System.out.println(ObjectSizeFetcher.getObjectSize(new C()));
}
}
Invoke with:
java -javaagent:ObjectSizeFetcherAgent.jar C
Space (not time) efficient. You could:
1) Define two stacks beginning at the array endpoints and growing in opposite directions.
2) Define the third stack as starting in the middle and growing in any direction you want.
3) Redefine the Push op, so that when the operation is going to overwrite other stack, you shift the whole middle stack in the opposite direction before Pushing.
You need to store the stack top for the first two stacks, and the beginning and end of the third stack in some structure.
yeah ! i solved it.
- jayram singh October 11, 2012can u plz elaborate it??
- jayram singh October 10, 2012check the question again..
- jayram singh September 17, 2012As both the trains are running with same speed..... they will meet in the tunnel only after they reach half of the tunnel... and as the length of tunnel is L the distance covered will be ( L/2 ) for each train. the time taken will be ((L/2) / V)... that means L/2V..... now as the particle is running with speed v it has a position at (L/2V)*v...
so the answer is ----> Lv / 2V
Void Insert(Node N)
{
if (head == null) // linked list is empty
{
head = N; tail = N; tail.Next = head;
}
else
{
Node temp=head;
while(N<=temp)
{
temp = head.Next; // since this is circular tail will point to head
}
head.Next = N;
N.Next = temp; // correct
}
}
@Abhishek S ... hey thanks for the modification....i need to modify my code..
- jayram singh September 04, 2012no Mr. i m not gonna sort at each insertion.... firstly i will sort that link list and then i m gonna insert into it...
- jayram singh September 04, 2012yup Mr. Anonymous....
cant u sort that link list...
if u can ... use my code to insert a value in it...
else
tell me i will give u code for sorting too...
Type& findMiddleNode()
{
int check = 0;
nodeType *current;
nodeType *mid;
current = first;
mid = first;
while (current != NULL)
{
current = current->link;
check = (check + 1) % 2;
if (check == 0)
mid = mid->link;
}
return mid->info;
}
The key here is that 1 million phone numbers will be within some range, likely 10 million or so. 10 million bits = 10^7 bits ~ 0.12 GB. Just have a bit array where the first bit being set implies that the first phone number is set (e.g., 10 000 000) and the last bit indicates the last phone number (10 999 999). If you find a number in the list, just set the appropriate bit. You now have a bit vector of size 1million bits, sorted, and to check for a particular number, you just check whether the corresponding bit is set.
- jayram singh September 04, 2012Void Insert(Node N)
{
if (head == null) // linked list is empty
{
head = N; tail = N; tail.Next = head;
}
else
{
Node temp = tail.Next; // since this is circular tail will point to head
Tail.Next = N;
N.Next = temp; // correct
tail = N;
}
}
Web browsers commonly allow you to navigate through a "history" of web pages that have previously been visited. The mechanism is somewhat like a stack, in that the most recently visited pages are at the top of the history and revisited when the "back" button is pressed.
However, the history does not necessarily have unbounded capacity. In reality, there may exist a fixed limit on the size of the history. The issue arises as to what should happen when the capacity is exhausted and a new item is pushed onto the stack. One possibility is to throw an exception. But this is not how a Web browser behaves. If it only has room to save 50 pages in its history and yet you visit more pages, it will make room in the history for a new page by throwing away the page that is on the very bottom of the history (i.e., the least recently visited page). The formal Stack interface does not help, as it gives us no way to directly access or remove the object on the bottom of the stack.
crontab -l
- jayram singh September 01, 2012a value of type "void *" cannot be assigned to an entity of type "char *"
- jayram singh August 29, 2012a value of type "void *" cannot be assigned to an entity of type "char *"
aaa
- jayram singh August 29, 2012b=malloc(10*sizeof(char));
a value of type "void *" cannot be assigned to an entity of type "char *"
Inorder traversal of any tree is already sorted....isn't it?
- jayram singh June 21, 2013