#!process zon final (im so cooked)
1 messages · Page 1 of 1 (latest)
I just took it
oh howd it go
had 4 behavioral 1 technical
kinda choked one of the behaviorals gave a bad response
hoping that doesn't mess me up
cad or usa?
how was the technical
AWS?
lol I interviewed for CAN but my interviewer was in the us
do you remember your techincal question?
was this one
I got optimal solution after a hint or 2 but it took me a while to write it up so idk
@ember trellis
no
no
yea similar user analyze visit
i had the same leetcode question
I said the wrong time complexity tho
oh my interviewer said
did u say nlogk
o(nm) i said o(n)
assume its srted
ohh
mine gave me a function to sort it
oh
if we r assuming its sorted
its o(n) right
nvm its still nm
did u use a sliding window approach
idk i thought it would be o(n) where n is amount of entries
ye
its n m cuz if n is the amount of like users and then m is the everage amount of pages each user visited
wouldn't it be o(n) if n is amount of entries
im ngl
since it would be like 3n
heap to store the top k most freq sequences right? (-count, sequence)
u guys used a heap?
i just stored it in a hashmap instead
cuz looping through the hashmap at the end is another O(N)
i didnt do the prob
instead of heap
same
cuz u cant call the max function cuz u need the key
or atleast idk how u would call the max function on the values and get they key in pyto=hon
but max function would give u the max count then in the for loop if you see that max count you can add it to ur result
Idk if that’s what u meant tho
yea
i didnt call the max thing
i looped through and everytime i would see a greater value,
i stored the key
my interviwer said return a list of strings
so if i saw a new value greater than mine
i would do
while len(list) > 0:
list.pop()
from collections import defaultdict, Counter
logs = [
{'user': '1', 'page': 'A'},
{'user': '2', 'page': 'B'},
{'user': '1', 'page': 'B'},
{'user': '1', 'page': 'D'},
{'user': '2', 'page': 'A'},
{'user': '3', 'page': 'B'},
{'user': '3', 'page': 'D'},
{'user': '1', 'page': 'C'},
{'user': '3', 'page': 'C'},
{'user': '1', 'page': 'C'},
{'user': '2', 'page': 'C'},
{'user': '3', 'page': 'B'},
{'user': '1', 'page': 'A'},
{'user': '3', 'page': 'C'},
]
def get_history_by_user(logs):
history = defaultdict(list)
for log in logs:
history[log['user']].append(log['page'])
return history
def get_history_combinations(history):
combinations = Counter()
for pages in history.values():
if len(pages) < 3:
continue
for i in range(len(pages) - 2):
sequence = tuple(pages[i:i+3]) # Use tuple to make it hashable
combinations[sequence] += 1
return combinations
def get_max_combination(combinations):
max_count = 0 # Stores the highest count found
max_sequence = None # Stores the sequence corresponding to the highest count
for sequence in combinations: # Iterate over all sequences
count = combinations[sequence] # Get the count for this sequence
if count > max_count: # If it's the highest count so far, update
max_count = count
max_sequence = sequence
return max_sequence # Return the most frequent sequence
history = get_history_by_user(logs)
combinations = get_history_combinations(history)
most_popular_sequence = get_max_combination(combinations)
print(most_popular_sequence)
or smth idr