Skip to main content

Snapchat backend engineer google hangout interview

1/16/17

--------------------------
_node1.log:_
...
2017-01-16 10:37:48.717 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:37:49.677 Snapchat[12345:1234567] Something something xyz.
2017-01-16 10:37:49.717 Snapchat[12345:1234567] Something something zyx.
2017-01-16 10:37:50.200 Snapchat[12345:1234567] Something something Bar.
2017-01-16 10:37:51.300 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.301 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.711 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.711 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.717 Snapchat[12345:1234567] Something something Foo.
...

_node2.log:_
...
2017-01-16 10:37:48.716 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:37:49.678 Snapchat[12345:1234567] Something something xyz.
2017-01-16 10:37:49.718 Snapchat[12345:1234567] Something something zyx.
2017-01-16 10:37:50.201 Snapchat[12345:1234567] Something something Bar.
2017-01-16 10:37:51.300 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.301 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.811 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.811 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:53.717 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:38:48.716 Snapchat[12345:1234567] Something something something.
2017-01-16 10:38:49.678 Snapchat[12345:1234567] Something.
2017-01-16 10:38:49.718 Snapchat[12345:1234567] Something zyx.
2017-01-16 10:38:50.201 Snapchat[12345:1234567] Something Bar.
2017-01-16 10:38:51.300 Snapchat[12345:1234567] Something Foo2.
2017-01-16 10:38:52.301 Snapchat[12345:1234567] Something Fuzz2.
2017-01-16 10:38:52.811 Snapchat[12345:1234567] Something Buzz2.
2017-01-16 10:38:52.811 Snapchat[12345:1234567] Something Bash2.
2017-01-16 10:38:53.717 Snapchat[12345:1234567] Something Foo.
...

_Output File (From aggregating the input files above):_
...
node1.log 2014-10-19 13:37:48.717 Snapchat[12345:1234567] Something something Foo.
node2.log 2014-10-19 13:38:01.454 Snapchat[12345:7654321] Something something Foo2.
node2.log 2014-10-19 13:38:02.600 Snapchat[12345:7654321] Something something Bar2.
node1.log 2014-10-19 13:38:50.200 Snapchat[12345:1234567] Something something Bar.
node2.log 2014-10-19 13:38:50.201 Snapchat[12345:7654321] Something something Baz2.
node1.log 2014-10-19 13:38:51.392 Snapchat[12345:1234567] Something something Baz.
...

So we want to implement a function :

public File logAggregator (File... files) {
     // TODO
}

That takes in some list of files and outputs the unified log output sorted by timestamp


STDIN:

node1.log:
2017-01-16 10:37:48.717 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:37:49.677 Snapchat[12345:1234567] Something something xyz.
2017-01-16 10:37:49.717 Snapchat[12345:1234567] Something something zyx.
2017-01-16 10:37:50.200 Snapchat[12345:1234567] Something something Bar.
2017-01-16 10:37:51.300 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.301 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.711 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.711 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.717 Snapchat[12345:1234567] Something something Foo.


node2.log:
2017-01-16 10:37:48.716 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:37:49.678 Snapchat[12345:1234567] Something something xyz.
2017-01-16 10:37:49.718 Snapchat[12345:1234567] Something something zyx.
2017-01-16 10:37:50.201 Snapchat[12345:1234567] Something something Bar.
2017-01-16 10:37:51.300 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.301 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.811 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.811 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:53.717 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:38:48.716 Snapchat[12345:1234567] Something something something.
2017-01-16 10:38:49.678 Snapchat[12345:1234567] Something.
2017-01-16 10:38:49.718 Snapchat[12345:1234567] Something zyx.
2017-01-16 10:38:50.201 Snapchat[12345:1234567] Something Bar.
2017-01-16 10:38:51.300 Snapchat[12345:1234567] Something Foo2.
2017-01-16 10:38:52.301 Snapchat[12345:1234567] Something Fuzz2.
2017-01-16 10:38:52.811 Snapchat[12345:1234567] Something Buzz2.
2017-01-16 10:38:52.811 Snapchat[12345:1234567] Something Bash2.
2017-01-16 10:38:53.717 Snapchat[12345:1234567] Something Foo.

# def logAggregator (file1, file2):
#     # mydict = defaultdict(list)
#     mylist1 = mylist2 = []
#     for line in open(file1, 'r'):
#         # mydict[file1].append(line)
#         mylist1.append((line, file1))

#     for line in open(file2, 'r'):
#         # mydict[file2].append(line)
#         mylist2.append((line, file2))

#     mylist = mylist1 + mylist2
#     mylist = sorted(mylist)

#     output = [ (y, x) for (x, y) in mylist]

import sys
def logAggregator ():
    mylist = []
    for line in sys.stdin:
        if 'node1.log' in line:
            tag = 'node1.log'
            continue
        if 'node2.log' in line:
            tag = 'node2.log'
            continue
        if not line:
            continue
        mylist.append((line, tag))

    mylist = sorted(mylist)
    return [ (y, x) for (x, y) in mylist]

myoutput = logAggregator()
for (x,y) in myoutput:
    print x, y,

Comments

Popular posts from this blog

CKA Simulator Kubernetes 1.22

  https://killer.sh Pre Setup Once you've gained access to your terminal it might be wise to spend ~1 minute to setup your environment. You could set these: alias k = kubectl                         # will already be pre-configured export do = "--dry-run=client -o yaml"     # k get pod x $do export now = "--force --grace-period 0"   # k delete pod x $now Vim To make vim use 2 spaces for a tab edit ~/.vimrc to contain: set tabstop=2 set expandtab set shiftwidth=2 More setup suggestions are in the tips section .     Question 1 | Contexts Task weight: 1%   You have access to multiple clusters from your main terminal through kubectl contexts. Write all those context names into /opt/course/1/contexts . Next write a command to display the current context into /opt/course/1/context_default_kubectl.sh , the command should use kubectl . Finally write a second command doing the same thing into ...

OWASP Top 10 Threats and Mitigations Exam - Single Select

Last updated 4 Aug 11 Course Title: OWASP Top 10 Threats and Mitigation Exam Questions - Single Select 1) Which of the following consequences is most likely to occur due to an injection attack? Spoofing Cross-site request forgery Denial of service   Correct Insecure direct object references 2) Your application is created using a language that does not support a clear distinction between code and data. Which vulnerability is most likely to occur in your application? Injection   Correct Insecure direct object references Failure to restrict URL access Insufficient transport layer protection 3) Which of the following scenarios is most likely to cause an injection attack? Unvalidated input is embedded in an instruction stream.   Correct Unvalidated input can be distinguished from valid instructions. A Web application does not validate a client’s access to a resource. A Web action performs an operation on behalf of the user without checkin...