Pramp - Busiest Time in The Mall

숲사람·2022년 6월 11일
0

멘타트 훈련

목록 보기
54/237

Pramp mock인터뷰 서비스다. 원하는 시간에 임의의 개발자와 매칭이 되며 서로 번갈아가며 인터뷰어 인터뷰이가 된다. 그래서 내일 처음 인터뷰어가 되어본다. 아래는 내가 내일 질문해야할 문제다. 인터뷰 24시간전에 메일로 공유된다. 미리 문제도 풀어보고 준비를 해야한다. 참고로 내가 당일 풀어야할 문제는 사전에 알수없다(실제면접과 동일 환경).

문제

쇼핑몰 door 검출기를 통해 추출된 시간별 입장/퇴장 data가 존재한다고 하자. data가 [시간, 인원수, 입장/퇴장] 으로 주어질때(입장1, 퇴장0), 몰에 가장 사람이 많이 존재하는 타임은 언제인가?

숙지해야할 Constraints

  • data는 시간순으로 정렬되어있다.
  • door가 여러개가 있을 수 있다! 따라서 동일 시간에 해당하는 입장/퇴장 데이터가 여러개 있을수 있다. 이 경우 해당 시간대의 모든 인원수를 입퇴장을 합한 결과가 해당시간 총 인원수다. 가령 아래의 경우 1487799425 시간에는 최종 8명(14 - 4 - 2) 이다.
[1487799425, 14, 1], 
[1487799425, 4,  0],
[1487799425, 2,  0],
  • 따라서 동일 시간대의 최종 인원수를 알아내는 코드를 작성하는것이 이 문제의 핵심 포인트
  • 동일 인원수에 중복된 시간이 있다면 빠른 시간을 리턴
input:  data = [ [1487799425, 14, 1], 
                 [1487799425, 4,  0],
                 [1487799425, 2,  0],
                 [1487800378, 10, 1],
                 [1487801478, 18, 0],
                 [1487801478, 18, 1],
                 [1487901013, 1,  0],
                 [1487901211, 7,  1],
                 [1487901211, 7,  0] ]

output: 1487800378 # since the increase in the number of people
                   # in the mall is the highest at that point

면접관으로써 유의사항

  • 함수명 변수명 잘 사용하는지
  • valid input range 체크, edge cases
  • 인터뷰이가 문제를 잘 풀 수 있도록 도와주는 역할을 해야함.
  • 잘못된 방향으로 풀때 힌트를 주거나 코칭 해줘야함.
  • 코딩 시작전에 해결 아이디어 토론하기.
  • 시간/공간 복잡도 어떤지 묻기

해결

동일시간대의 인원수를 모두 카운트 해야하기 때문에, 생각이 복잡해짐. 다음시간을 미리 체크하는게 중요.

데이터를 한번씩 순회하면서 다음시간이 현재시간과 동일한지 여부에 따라 다시 인원수를 카운트할지 max를 업데이트 할지 결정. 다음시간이 현재시간과 다를때만 max 를 업데이트 하면 된다.

시간순 정렬되어있기 때문에 데이터를 리니어한 타임에 확인이 가능하다. 따라서 시간복잡도는 O(N)이고 공간복잡도는 data갯수만큼 추가 데이터를 필요로 하지 않았기 때문에 O(1)이다.

/*
1. Constraints
 - buisest means maximun number of people at a time.
 - 1 ≤ data.length ≤ 100
 - data[i][2] == 1 is enterence
 - same visitor , return earlist one
 - update all in same time
2. Ideas
 - linear search and update max time and max people
3. Test cases
 - check same visitor data. return earlist 
*/

그리고 i+1 < dataArrayLength && 이부분 잘 작성하는지 확인해줄것.

#include <stdio.h>
#include <stdlib.h>

int findBusiestPeriod(size_t dataArrayLength, int const data[dataArrayLength][3]) 
{
  int max_p = 0;
  int curr_p = 0;
  int max_time = 0;
  
  for (int i = 0; i < dataArrayLength; i++) {
    /* 1. update count */
    curr_p = data[i][2] == 1 ? curr_p + data[i][1] : curr_p - data[i][1];
    
    /* 2. check next timestapmp is same with current */
    if (i+1 < dataArrayLength && data[i][0] == data[i+1][0])
      continue;    
    
    /* 3. update maximum */
    if (curr_p > max_p) {
      max_p = curr_p;
      max_time = data[i][0];
    }
  }
  return max_time;
}

int main() {
  return 0;
}

Wrapup Interveiw

  • 인터뷰어가 되어보는 경험을 통해 상당히 많은 것을 배웠다. 아래 두가지를 더 훈련해야할 것같다.

    • 면접관이 되기 전에 문제를 정확히 이해하고 다양한 예제(코너케이스를 잘 설명해줄 수 있는)를 제공해줄 수 있어야함.
    • 남이 짠 코드를 잘 따라가고 이해할수 있어야함. (답안이 내가 생각하지 못한 해답이었는데 코드가 살짝 복잡해서 따라가는데 살짝 햇갈렸다.)
  • 다음은 내가 해준 피드백 FEEDBACK FOR YOUR PEER

  • Problem Solving: How were your peer's problem solving skills?
    ' ' ' ' Amazing
    Got an optimal solution with minimal guidance

  • Coding: How were your peer's coding skills?
    ' ' ' 'Strong
    Works but not quite readable, reusable or maintainable

  • Communication: How were your peer's communication skills?
    ' ' ' 'Amazing
    Every single bit was crystal clear

  • What are your peer's strengths? What impressed you?
- The process before starting coding was excellent
    - checking example/ discuss solutions / check complexity
- Talking about your thinking process during coding.
- Changing the solution idea from using a hashtable to linear search due to the inefficient space complexity.
- Solve the problem even if it is a complicated code flow.
- Easily found a bug or problem by yourself.
- No compile error when you finished a code.
  • What wasn't as good?
    What should your peer improve? How would you advise them to get better?
- The code flow could be more simple (but I am impressed you can write code under complex code flow).
  • How did your peer perform as your interviewer?
    Were they respectful and useful to you? Did they seem prepared to ask their question(s)?
    ' ' ' ' Great
Give an appropriate hint at the right time with good examples due to your well understanding the question. 
I was nervous because of my lack of experience of coding interview. 
But you make the interview very comfortable. Thank you!
profile
기록 & 정리 아카이브 용도 (보다 완성된 글은 http://soopsaram.com/documentudy)

0개의 댓글