S O U N D W A V E
BAN USER- 3 Answers How to delete an account?
I've emailed careercup support 5+ times already (no response) about having this account deleted. Does anyone work actively on this site at all?
- S O U N D W A V E November 27, 2013
I occasionally get emails for recent comments to questions even though I'm not subscribed to this.
The unsubscribe link in this email leads to nothing useful (as I'm not subscribed to this service to begin with).
How do I contact the people who run careercup? How to stop the sporadic spam emails?
I just got this email (which is considered spam now) :
undefined has commented on a question.
You are given an array in which you’ve to find a subarray such that the sum of elements in it is equal to zero.
He algo is nice.
However, In java it is not easy using the hashMap to get the key of values if we use hashmap(index,value). And if we want to use hashtable(value,index), the array cannot have dup as it will have the same key and cover the previous value. We can use a biMap to handle it.
if we don't want to use biMap here is my solution using two hashMap.
static void sumEqZero()
{snip}
View » | To unsubscribe, login and click here.| Flag | PURGE
It covers the [x, x, .... ], K>0 case
but I think it misses the [x, x, ... ], K=0 case.
Maybe this:
public static int getDiffPair(int a[] , int diff){
HashMap<Integer,Integer> hashMap = new HashMap<Integer,Integer>();
int count = 1;
for(int i = 0;i<a.length;i++){
if(hashMap.containsKey(a[i])){
count = hashMap.get(a[i]);
hashMap.put(a[i], ++count);
}else{
hashMap.put(a[i], 1);
}
}
count = 0;
for(int j = 0;j<a.length;j++){
if(hashMap.containsKey(a[j]+diff)){
count+=hashMap.get(a[j]+diff) - (!diff ?1:0); //changed
}
}
return count;
}
In that case:
- Augment each node with "succ" pointer.
- Augment insert/delete/rebalance operations to keep "succ" pointer valid
-> E.g. if you insert a node, walk down it's right subtree, or if it doesn't have one, use parent pointers to find succ., then fill the "succ" pointer
-> Now create a succ(reference/pointer to node) function that returns the succ. in O(1) time... O(1) time is still O(1) amortized
The question is ambiguous (check my post of clarifying questions).
There are many, many factors involved. Both of you "assumed" the factors based on whatever version of "inorder successor" you each had experience with.
It depends.
1) Are you given a key or a node(address/reference)?
2) Are there parent pointers?
3) Do you mind O(n) or do you insist on O(lg n)?
^^^ Yes, because all growing shortest paths start at a G and go through a '0' (they do not revisit a numbered node again).
My "Lol" comment above was referring to this fix:
A[i+u][j+v]=A[i][j]+1;
should be
A[i+u][j+v]= (A[i][j]=='G')? 1: A[i][j]+1;
@Mem, took a closer look, and I see what you are doing here. You are repeatedly trying all paths, even if they reuse the same spots, so long as going through the spot is cheaper than any previous path through that spot.
Cool idea!
The idea should work but it worst case complexity should be large.
Paint fill is boolean filling of nodes...so dfs vs.bfs has same effect because u are just visiting all suitable nodes.
This is shortest distance filling... So dfs usually does not work.
Lol treat G as 1 inside while loop
- S O U N D W A V E March 10, 2014I am not sure :(
How can you guarantee that "step" is always the shortest path reachable from that guard? Can you explain it?
Yes, I noticed when he asked for code even after a hint was given.
Why do people do this? Is that website giving money or something?
@Mem, recursion would go deep in one direction before trying others (i.e., DFS).
- S O U N D W A V E March 10, 2014Dijkstra's is not needed as this is a "every move/edge is 1 unit of weight" problem.
- S O U N D W A V E March 10, 2014DFS goes deep as far as it can in one direction, before trying others.
- S O U N D W A V E March 10, 2014Typed it in directly... so expect bugs (or plain incorrectness :P )
BFS initiated from all guard positions and +1 for reaching a naked position (a '0') and add it to queue to keep the BFS search going.
//Assuming N x N matrix and directions are up/down/left/right
#define IN_BOUNDARY(a,b) ((a)>=0 && (a)<N && (b)>=0 && (b)<N)
typedef struct { int x, y; } Pos; //struct for a "position" of a node (indices)
//find and enqueue guard positions
queue <Pos> Q;
Pos temp;
int i, j;
for (i=0; i < N; i++)
for(j=0; j < N; j++)
if( A[i][j] == 'G' ) {
temp.x=i;
temp.y=j;
Q.push(temp); //putting guard position in Q
}
//BFS
while(!Q.empty()) {
temp=Q.front(); Q.pop();
i=temp.x;
j=temp.y;
for( int u=-1; u < 2; u++)
for( int v=-1; v < 2; v++)
if( (!u||!v) && IN_BOUNDARY(i+u, j+v) && A[i+u][j+v]=='0')
{
//should reach here for only/all valid naked neighbours
A[i+u][j+v]=A[i][j]+1; //distance to neighbour is 1 more
temp.x=i+u;
temp.y=j+v;
Q.push(temp); //push neighbour onto queue
}
}
a[3] is a garbage valued (because it is coming off stack) pointer to a char
when it's passed to printf, printf will try to access characters a[3][0] then a[3][1] ... etc. until some a[3][k] is the '\0' character (signalling end of string).
if you are lucky and say a[3][0] just happens to be '\0', then there is a[4] garbage pointer to deal with on next iteration of the loop
You are good enough for Google Research (or Google X) though.
Evidenced by the loads of useless non-interview questions you've posted on cc:
careercup.com/user?id=5728613638864896
LOL what? Input from user?
Right end? Second corner?
Which reaches first? HUH
Yes it's stupid and useless interview question.
30 min. to invent something while nervous, yet the answers are pointing to published papers.......
input: {1,2,1,2}, L=2
output: ???
Who asked you this at Google? We need to notify the hiring committee of this interviewer.
- S O U N D W A V E March 10, 2014Is the graph Undirected (i.e., adj matrix is symmetric) ?
Maybe we can treat the 0's as edges and invoke regular maximal clique algorithm (which treat's 0's as edges and 1's as nonedges).
What is the question?
Which company uses "void main" ?
think what happens printf tries to print a[3]
For illustrative purposes only:
#include <stdio.h>
int main()
{
int i = 0, j = 0;
char *a[10] = {"hi", "hello", "how"};
for(j=3; j<10; j++) a[j]="";
a[0] = "hey";
for (i = 0; i < 10; i++)
printf("%s\n", a[i]);
return 0;
}
If it was clear why did you keep changing your original post as people asked you questions and kept posting code that was misled by your ambiguity?
Which Amazon location asked you this? Did you ask them clarifying questions? What did they say exactly? Why aren't these in your post?
Pavi, you don't even know what the question is, so stop wasting people's time.
- S O U N D W A V E March 09, 2014If you knew all this, why would you not friggen save people's time and post it in the original question?
- S O U N D W A V E March 09, 2014You will never find out.
Life isn't merit based, it's only slightly so.
Move on to the next opportunity :)
I heard she approves every hire (quick glance at package).
If your resume is full of big names or famous schools, then you are more likely to catch her attention in the 1 min. she might give your package.
Check your code carefullly. First of all, how can you return nothing in the base case?
Secondly, think about leaf nodes.
I don't not fully understand the question precisely. What about leaf nodes?
Are you saying only the leaf nodes have values that can vary, and the rest of the tree just ripple sums these up to root?
Anyways, for the restriction, why can't you define your own += using a loop on ++ ?
he's trying to use the fact that
(x/y) = e^log(x/y) = e^{logx - logy}
but he should test his code, especially with y==0 (log 0 == infinity?)
if(str.length < 1 ) //rubbish;
char c=str[0]; //character of current run
char max_c=c; //character of maximum run
int pos=0; //position (index) of beginning of current run
int max_run=1; //length of maximum run
for(int i=1; i<str.length; i++)
{
if(str[i] != c) { //we've exited a run
if(i-pos > max_run) max_run=i-pos, max_c=c; //update max info if needed
c=str[i], pos=i; //regardless, mark the start of new run
}
for(int i=0; i<max_run; i++) putchar(max_c);
Fisher Yates modified:
for(int i=0; i<K; i++)
{
pos=rand_inclusive(i, A.length-1);
R[i]=A[pos];
A[pos]=A[i];
}
return R; //this line is psuedo-code or Java
Fisher Yates modified:
for(int i=0; i<K; i++)
{
pos=rand_inclusive(i, A.length-1);
R[i]=A[pos];
A[pos]=A[i];
}
return R; //this line is psuedo-code or Java
There is a different between testing(TE) and dev jobs.
Not so much betwen S(D)ET and SWE at lower levels though.
But as your career progresses, ask yourself this question: How many upper level managers are there from testing vs. dev backgrounds?
Would the VP of Engineering at a company more likely to have been a TE or an SWE?
Another question: Is it just as hard to switch from dev to te as it is from te to dev?
Nope.
Why???????
If I can guess the details...
A first solution is to build all valid RPN strings and do Edit Distance on each and keep track of min.
{Note a valid input string should have 1 more operand than operator}
You can build all valid RPN strings from right to left using backtracking.
You have two total variables numoperators, numoperands (we know numoperators == numoperands-1 for valid inputs).
Now everytime you place an operator, decrement numoperators, similarly do for operands.
You can only place an operator if numoperators > 0.
You can only place an operands if numoperands > numoperators+1.
You didn't type your question properly to begin with. Many ambiguities:
1) Do all the x's denote the SAME operand?
2) How can you guarantee that a unique postfix RPN form exists?
Some inputs will have none, some will have multiple.
xxx** and xx*x* are both valid RPNs that can be mutated from **xxx
What does "how many (mutation operations) are needed to make the string follow _the_ RPN" mean? "the" RPN????
0. Open algorithm book to pages explaining Shunting Yard and Edit Distance... then..
1. Use Dijkstra's Shunting Yard Algorithm to convert from infix to postfix
2. Return Edit Distance (DP) {with costs 1, 1, 1 for three operations} between infix and posfix
return inversions1 + inversions2 + inversions_crossing;
*
- S O U N D W A V E March 03, 2014Modify mergesort to return inversions also (while sorting the input array).
Normally mergesort returns "void" so you can make it return "int" to also return number of inversions.
The main change is to modify the merge routine inside mergesort (which usually returns nothing, but now will return an integer which is the count of the number of inversions BETWEEN elements in left array and right array).
When merging the left half array L and right half array R, we usually have two counters i_L and i_R pointing into the two arrays (pointing at the current numbers we are comparing and considering for placement in the output array).
So when you do the comparison, if L[i_L] <= R[i_R], you will move L[i_L] into the merged array as normal and increment i_L++. So no change for this case (please note, include the = case as part of this case, not the next one).
What is different now is if L[i_L] > R[i_R], you will move R[i_R] .. blah blah as usual but you will ALSO increment a counter like: crossing_count += L.length - i_L
Why? Because the element R[i_R] you are moving into merged array is inverted with respect to all the remaining elements in the L array (and there are L.length - i_L ) of them.
So that's what you do. You modify merge subroutin to increment a counter whenever something from the the right array is picked to be placed in the merged array. And you increment it by the number of remaining elements in the L array. Convince yourself that this will count ALL the crossing inversions (inversions between elements in L and R).
How does it look overall when the new merge function is placed in mergesort?
// return value is the number of inversions in array A[start..end]
int mergesort( double A[ ], int start, int end )
{
if( start >= end ) return 0;
int mid = low + (high - low)/2;
int inversions1 = mergesort(low, mid); //how many in left array
int inversions2 = mergesort(mid+1, high); //how many in right
int inversions_crossing = merge(A, low, high, med); //how many crossing type?
return inversions1 + inversions2 + inversions3;
}
G is the overall graph object instatiated from a class/struct "Graph" .. wrapping everything up.
It represents whole graph.
//for e.g. (some parts of setup, minimalistic- no member functions)
#define MAX_VERTICES 100000
struct Graph {
int numVertices; // number of actual vertices
struct Vertex {
bool visited;
//other stuff (maybe adj list , edges, etc.)
//some data
} vertices[MAX_VERTICES]; //or make it dynamic array
//some more stuff
};
bool isTree(Graph *G)
{
if(G->numVertices == 0) return true; /* empty tree ? :) */
/* Step 1: pick a random vertex and reset visit flags somehow */
int v = //PICK RANDOM INDEX NUMBER from 0 to G->numVertices-1
// for(int i=0; i < G->numVertices i++) G->vertices[i].visited = false;
Stack <int> S;
/* DFS to check for cycles - f you meet a visited node ==> cycle found */
S.push(v); //v is random start node we picked earlier
while( !S.empty ) {
v = S.pop();
if( G->vertices[v].visited )
return false; //cycle found (not a tree)
G->vertices[v].visited = true;
for( all edges (v, u) from vertex v)
S.push(u);
}
/* Step 3: If any vertices are unvisited, graph is disconnected == not a true */
for(int i=0; i < G->numVertices i++)
if( ! G->vertices[i].visited )
return false;
return true; //passed both tests, so it is a tree
}
Trees do not have parent nodes.
You are speaking of any possible "root" node (special node designated as root).
Well the question says the edges are undirected, so a "child" can reach its parent node, so any node can reach the root node (it is sort of like having parent pointers in the rooted binary tree you are imagining).
Just DFS from every starting position looking for a matching word along valid paths and as you visit nodes/letters, capitalize them ( c = c + 'A' - 'a') to mark them as visited, and decapitalize them when unwinding.
- S O U N D W A V E February 28, 2014People sometimes give politically correct answers. Also most companies would probably would LOVE to hire you as a test engineer, so remember this bias when considering their answers.
It is generally much easier and more benefitial to do a QA/TEST --> DEV transition within the same company. Much easier.
Easy modification? Add some DS calls to code.
- S O U N D W A V E February 28, 2014You love coding and not testing == Developer, no?
- S O U N D W A V E February 28, 2014explain?
- S O U N D W A V E February 28, 2014It's random psuedo/english based code.
I don't know what your talking about either :P
Please explain.
let i be row number (0 to N-1), and j be col number (O to N-1)
diagonal 1 has i+j =0
diagonal 2 has i+j =1
...
So define D = i+j
Loop with D from 0 to 2*(N-1)
Now if D = i+j then j=D-i
So we have reduced the problem to two variables: D and i (two loops)
for D from 0 to 2*(N-1)
{
for i from 0 to D
print(A[i][D-i])
println();
}
Check for bugs. And thanks for posting this fun question.
You can think of the MxN case
Repmylakleinm, Quality Assurance Engineer at Coupon Dunia
Articulate and accomplished admin executive experience at keeping an office running smoothly. A communicator and collaborator who is efficient in ...
Repherminanmuller87, Animator at 247quickbookshelp
Hello,I am a literacy teacher. I completed my degree from Chicago and now am a literacy teacher in a ...
Repjanistbennett, Blockchain Developer at AMD
I am JanisBennett working as a journalist, having years of experience in my career. I have covered various stories.Great ...
Repgarlandkrebs, Animator at ADP
Highly focused and seasoned magazine editor with vast experience in all stages of weekly and monthly magazine production. My aim ...
Repannawellson007, Area Sales Manager at 8x8
Hey my name is anna And i am working as a content writer in Search engine optimization company.My component ...
Repneshujaha, Member Technical Staff at BMO Harris Bank
I am Neshu, a Camera Operator with a creative eye for detail and dedication to quality work. I am always ...
RepLooking for the best child development center in Charlotte? Pal A Roos provide summer camp for children Charlotte. Our experienced ...
RepRobertBaumbach, Administrative Manager at Meridian Mechanical Services
Reprafaeltanner210, Associate at 247quickbookshelp
I am Labor relations directors, oversee employment policies in union and nonunion settings. I draw up, negotiate, and administer labor ...
Repcolettehenna, OOPS Freshers at Bosch
I am Colette , policy analyst at Sunflower Market , with 3 years of experience building and maintaining relationships with elected officials ...
RepIndianastrologyguru, Data Scientist at ABC TECH SUPPORT
Hey I'm Shelly Renee and I'm working as a system developer. Currently working part time on a project ...
Repelisahbuff, Apple Phone Number available 24/7 for our Customers at Altera
I have previous work experience in a customer focused environment. I like to Enjoy my Free Time Playing football.I ...
Reptaylamowll, Analyst at AMD
Aspire to work in a challenging environment, where my exceptional skills and abilities are completely explored, and I can easily ...
Repamayalopez800, Accountant at A9
I am Amaya ,working in the field of training and development coordinator for three years, focusing on teaching English as ...
Reploragurrero, Research Scientist at Absolute Softech Ltd
I am Lora , an empathetic and dedicated Community Organizer with a deep passion for helping others and a strong determination ...
RepKellyLabbe, Animator at Future Advisor
My name is Kelly and I am currently a freshman Fitness trainer in Vibrant Man company .I have learned a ...
Repkarinkwalton, Backend Developer at Broadsoft
I am working as a Support clerk in an MVP Sports company. I love traveling and exploring facts about technology ...
RepTimothyAYocum1, Android Engineer at ABC TECH SUPPORT
I am a medical or osteopathic doctor who specializes in eye and vision care. My work Ophthalmologists differ from optometrists ...
RepGinaSanchez, Computer Scientist at Autoportal.com
Ginna from New York.Successfully managing a high volume of work assignments without compromising quality to exceed client expectations.Apart ...
RepDonnaArvin, Analyst at Apple
Hii am from the United States. I work as a computer control programmer at Dynatronics Accessories. I am a social ...
Reppamilarbowman, Animator at ABC TECH SUPPORT
Je travaille en tant que Web Manager dans la société Forum Cafeterias. Je veux tout savoir sur le marketing numérique ...
Java doesn't have a "multiset" (I don't think) like C++ does, so the standard way is to simulate it with "Map<item type, int(for counting)>"
- S O U N D W A V E March 12, 2014Instead of just inserting any item, you first check if it's in the Map, and if it is, increment the value(which is the count).