lngbrc
BAN USER
- 2of 2 votes
AnswersWAP to sort prime numbers smaller than given N by digits. If N is 40, the output should be 11, 13, 17, 19, 2, 23, 29, 3, 31, 37, 39, 5, 7.
- lngbrc in United States
Follow-up question: limit memory usage.| Report Duplicate | Flag | PURGE
Amazon Senior Software Development Engineer Math & Computation
Firstly, need to ask interviewer to clarify:
- # of log entries/day, # of pages and # of users? can the data fit into a traditional DB or requires distributed storage. I assume the analyzed results can be loaded into an RDBMS.
- is this real-time analysis or can we use a Hadoop job to ETL? I assume ETL is allowed.
- should we optimize for query performance or write performance? I assume query performance is more critical.
The solution is to write raw log data to HDFS, using Apache Flume to support multiple data centers. Use Hadoop job to analyze the raw data and load results into an RDBMS for query.
In RDBMS, to support the first two queries, we can use a table with columns "page, user-count, visit-count". For third query, we can create a table with "page, user-id, count".
for (int i = 0; i < tgt.length; i++) {
if (tgt[i] == 0) continue;
int pos = findPos(src, tgt[i]);
if (i == pos) continue;
int posZero = findPos(src, tgt[i]);
if (posZero != i) {
swap(src[posZero], src[i]);
}
swap(src[pos], src[i]);
}
an improvement maybe to cache zero position in src to avoid an lookup.
- lngbrc August 29, 2013I would use recursion to solve this problem:
public static boolean IsKPalindrom(char[] arr, int k) {
int match = 0;
if (arr.length <= 1) return true;
// try to match front and back of the string
for (match = 0; match < (arr.length / 2); match ++) {
if (arr[match] != arr[arr.length - match - 1]) {
break;
}
}
if (match >= (arr.length / 2) {
// Yeah!
return true;
} else if (k == 0) {
// not palindrom, and we cannot remove any more characters
return false;
} else {
// remove 1 char and call recursively
return isKPalindrom(arr.subarray(match + 1, arr.length - match - 1), k - 1) ||
isKPalindrom(arr.subarray(match, arr.length - match - 2), k - 1);
}
}
correction...
public static void Arrange(int[] arr)
{
int pos = 0;
int neg = 0;
for (int i = 0; i < arr.length; i ++) {
if (i%2 == 0) {
for (pos = max(pos, i); pos < arr.length; pos ++) {
if (arr[pos] > 0) break;
}
if (pos >= arr.length) break; // all remaining numbers are negative, exit
if (pos != i) {
swap(arr, pos, i);
pos ++;
}
} else {
for (neg = max (neg, i); neg < arr.length; neg ++) {
if (arr[neg] < 0) break;
}
if (neg >= arr.length) break;
if (neg != i) {
swap (arr, neg, i);
neg ++;
}
}
}
}
public static void Arrange(int[] arr)
{
int pos = 0;
int neg = 0;
for (int i = 0; i < arr.length; i ++) {
if (i%2 == 0) {
for (pos = max(pos, i); i < arr.length; i ++) {
if (arr[pos] > 0) break;
}
if (pos >= arr.length) break; // all remaining numbers are negative, exit
if (pos != i) {
swap(arr, pos, i);
pos ++;
}
} else {
for (neg = max (neg, i); i < arr.length; i ++) {
if (arr[neg] < 0) break;
}
if (neg >= arr.length) break;
if (neg != i) {
swap (arr, neg, i);
neg ++;
}
}
}
}
RepSophiaLopez, Analyst at AMD
I am a skilled freelance graphic designer with over a decade of experience in the field. I am dedicated to ...
Replisaramsey773, Blockchain Developer at Adjetter Media Network Pvt Ltd.
I'm a 27 year-old blogger, make-up junkie and follower of Christ.I love all things that bring happiness. My ...
Repmaryctedesco7485, Accountant at ABC TECH SUPPORT
Efficient Production Manager with 15 years of experience leading diverse manufacturing teams to create high-quality products at top speeds. Dedicated ...
RepAtharvFlores, Accountant at A9
I am working as a position of a court clerk to assist the judges as attorneys in expediting the court ...
RepRilynFreeman, Area Sales Manager at Knewton
Hi my name is Rilyn. Library assistant in Jeans Unlimited company. I help to keep libraries organised and efficient while ...
RepEsotaTaylor, abc at 8x8
I am working as a lecturer with exceptional teaching abilities seeking employment in your organization. I have excellent experience in ...
RepAaghnyaBrown, Accountant at 247quickbookshelp
Professional agile project manager with over 2 years of experience in various facets of project management. Implement agile management ideals ...
RepLicholsLowry, Associate at AMD
I am Lichols, I am an outreach worker in Desmonds Formal Wear company .I specialise in a variety of different ...
Repulrikefiedler789, Animator at 247quickbookshelp
Hello I am a journalist with 5 years of experience crafting timely, informative and factual stories with attention to complexity ...
RepCathyCruz, Analyst at AMD
I am a highly responsible service station manager seeking an opportunity to work in a top company oy aid in ...
RepEzraClark, Analyst at 8x8
I am an experienced multimedia journalist with a background in investigative reporting. I work well with photographers and videographers when ...
similar to "sort using two stacks" problem from "cracking..." book. treat the linked list as stack, and add another stack (linked list) to keep sorted results.
- lngbrc May 22, 2015