tazo
BAN USER- 5of 5 votes
AnswersGiven a number "n", find the least number of perfect square numbers sum needed to get "n"
- tazo in United States
Example:
n=12, return 3 (4 + 4 + 4) = (2^2 + 2^2 + 2^2) NOT (3^2 + 1 + 1 + 1)
n = 6, return 3 (4 + 1 + 1) = (2^2 + 1^2 + 1^2)| Report Duplicate | Flag | PURGE
Google Dynamic Programming - 2of 2 votes
AnswersYou are given a class name Person that looks like this
interface Person { boolean moveUp(); boolean moveDown(); boolean moveRight(); boolean moveLeft(); boolean found(); }
This person is standing somewhere in a cell (like a array index) inside a grid (a 2D array) of unknown size and unknown boundaries. Only given info to you is the Person object and in this unknown size grid you have a apple in some unknown cell, you have to reach to this apple in efficient way.
The methods available in the Person object will actually move the person to that cell if method returns true.
You have to implement a method
- tazo in United Statesvoid findApple(Person person);
| Report Duplicate | Flag | PURGE
Algorithm - 3of 3 votes
AnswersFind a given element in sorted array.
- tazo in United States
arr= [1, 2, 3, 4, 5, 6]
follow up: If the sorted array is shifted left by unknown number, modify existing binary search to find a element in modified array
arr = [4, 5, 6, 1, 2, 3]| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Arrays - 0of 0 votes
AnswersWrite a MapReduce job that takes in two text files, and output the probability that those two files are identical (with 0% -> completely different, 100% -> completely different).
- tazo in United States
Clarification: Matching should not be a per-line diff, but it's about the content. One article could be 80 characters per line in one version, but could be 100 characters per line in another version, for the same content. In that case, it should be 100% match even though, if you are comparing line by line, they are totally different.| Report Duplicate | Flag | PURGE
Yahoo Coding - 0of 0 votes
AnswersCount number of duplicated in a BST. Just print count at end or return count. Can't use HashMap or HashSet. Not supposed to any extra space
Example tree:5 / \ 3 10 / \ / \ 2 4 8 10 / / \ 3 5 8 \ 8
Answer for this is 5 (1 extra 3, 1 extra 5, 2 extra 8 and 1 extra 10)
- tazo in United States
EDIT: tree can't be modified. No extra space should be used. It should be O(n)| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswersDesign GMail's "consider adding" feature when writing an email. Assume you already have 1M emails of some user 'X'.
- tazo in United States
More explanation: When you write email in GMail and add a email to 'To:', you will get a option saying "Consider adding: alice, bob, john....". He asked me to design this feature.| Report Duplicate | Flag | PURGE
Software Engineer / Developer Algorithm
You can create a HashMap like HashMap<String, HashMap<String, String>> and store key and (user, value).
class Main {
static HashMap<String, HashMap<String, String>> map = new HashMap<>();
static void add(String user, String key, String value) {
if (map.get(key) == null) {
HashMap<String, String> map2 = new HashMap<>();
map2.put(user, value);
map.put(key, map2);
} else {
map.get(key).put(user, value);
}
}
static List<String> getUsers(String key) {
if (map.get(key) != null) {
return map.get(key).keySet();
}
return new ArrayList<String>();
}
}
I am a bit confused by the if condition
if(usableSig[i] == sig[i]){
return false;
}
doesn't this mean, if for words "ant" and "apple", you return false right away for 1st character and not check of rest ?
and also when you return true, you don't check anything, just coming out of for loop says the word can be formed with given characters ?
please explain, I might be overlooking something here.
import java.util.*;
import java.lang.*;
import java.io.*;
class Closest {
public static void main (String[] args) throws java.lang.Exception {
List<Point> points = new ArrayList<Point>();
points.add(new Point(-2, -4));
points.add(new Point(0, 0));
points.add(new Point(10, 15));
points.add(new Point(5, 6));
points.add(new Point(7, 8));
points.add(new Point(-10, -30));
System.out.println(closest(new Point(5, 5), points, 2));
}
private static List<Point> closest(Point x, List<Point> points, int n) {
List<Point> closest = new ArrayList<Point>();
Map<Double, Point> set = new TreeMap<Double, Point>();
for (Point p : points) {
double dist = getDistance(x, p);
System.out.println(p + "\t=>" + dist);
set.put(dist, p);
}
int counter = 0;
for (Map.Entry<Double, Point> entry : set.entrySet()) {
if (counter == n) {
break;
}
closest.add(entry.getValue());
counter++;
}
return closest;
}
private static double getDistance(Point a, Point b) {
return Math.sqrt(Math.pow((a.x - b.x), 2) + Math.pow((a.y - b.y), 2));
}
static class Point {
public int x;
public int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public String toString() {
return "("+x+","+y+")";
}
}
}
http: // ideone.com/3bNBga
- tazo December 21, 2014private List<List<Inetger>> powerSet(List<Inetger> numbers) {
List<List<Inetger>> ps = new ArrayList<List<Integer>>();
ps.add(new ArrayList<Integer>());
for (int n : numbers) {
List<List<Integer>> new_ps = new ArrayList<List<Integer>>();
for (List<Integer> subset : ps) {
new_ps.add(subset);
List<Integer> temp = new ArrayList<Integer>(subset);
temp.add(n);
new_ps.add(temp);
}
ps = new_ps;
}
return ps;
}
RepKarlDuffie, AOL tech support at 8x8
As an Information Architect with a passion for optimizing digital experiences, I thrive on organizing and structuring information to enhance ...
RepErickaLeibowitz, abc at 8x8
As a seasoned producer, my passion for music has propelled me through a dynamic career, marked by innovation and sonic ...
RepMarciaGonzalez, abc at ADP
I am a diligent Encoding Clerk with a passion for precision and accuracy in data management. With a keen eye ...
RepGladysPhillips, Associate at ADP
I have dedicated my professional career to fostering vibrant and harmonious communities.I have successfully navigated the complexities of community ...
RepCathyPotts, abc at 8x8
In my role as a Customer Services Manager, I excel in understanding the unique needs of clients and customers. I ...
This is wrong.
- tazo March 12, 2015Your code returns 3, 1, 1, 1 (4 numbers) but lowest number of numbers needed to make 12 is 2, 2, 2 (3 numbers)
Greedy solution doesn't work in this case.