Google
4.2 of 5 2,282 reviews
www.google.com Mountain View, CA 5000+ Employees

Google Software Engineer Intern Interview Question

I interviewed in Los Angeles, CA and was asked:
"flatten iterator"
Add Tags [?]
Answer Flag Question

Part of a Software Engineer Intern Interview Review - one of 2,998 Google Interview Reviews

Answers & Comments

1
of 2
votes
(newton-raphson)

public static float findzero()
{
    float delta = 0.01f;
    float epsilon = 0.00001f;
    float x = 0.0f;
    float fxn = f(x);
    while (Math.abs(fxn) > epsilon) {
        float fxnp = (f(x+delta) - f(x-delta)) / (2 * delta);
        x = x - fxn / fxnp;
        fxn = f(x);
    }
    return x;
}
- Rahul on May 5, 2013 Flag Response
1
of 2
votes
(flatten iterator)

public static Iterator flattenIterator(Iterator<Iterator> nested) {
    return new FIterator(nested);
}

class FIterator {
    Iterator currentIterator = null;
    Iterator<Iterator> nested = null;

    public FIterator(Iterator<Iterator> nested) {
        this.nested = nested;
    }

    public boolean hasNext() {
        while ( ((null != currentIterator) && (!currentIterator.hasNext())) ||
                ((null != currentIterator) && (nested.hasNext()))) {
            currentIterator = nested.next();
        }
        return (currentIterator != null);
    }

    public Object next() {
        if (!hasNext()) return null;
        return currentIterator.next();
    }
}
- Rahul on May 5, 2013 Flag Response

To comment on this question, Sign In with Facebook or Sign Up


Tags are like keywords that help categorize interview questions that have something in common.

Glassdoor is your free inside look at Google interview questions and advice. All interview reviews posted anonymously by Google employees and interview candidates.