codility Lesson 풀어보기 5

Coding Test 준비/codility 2022. 8. 15. 20:52

Codiliy Lesson 풀어보기 Day5.

 - 아직은 Easy 위주로 진행.

 - MVC 스프링 2편 완강 후 코딩테스트 진행

 

Codility Lesson 7. Stacks and Queues - Nesting

  - Stack을 사용해서 구현

https://app.codility.com/demo/results/training8U4TPU-2T8/

 

Test results - Codility

A string S consisting of N characters is called properly nested if: S is empty; S has the form "(U)" where U is a properly nested string; S has the form "VW" where V and W are properly nested strings. For example, string "(()(())())" is properly nested but

app.codility.com

 

 

Codility Lesson 7. Stacks and Queues - StoneWall

 - Stack을 사용해서 구현.

 - 문제가 이해가 안가서 인터넷 검색 찬스..☆

https://app.codility.com/demo/results/trainingS8Q4HB-BX3/

 

Test results - Codility

You are going to build a stone wall. The wall should be straight and N meters long, and its thickness should be constant; however, it should have different heights in different places. The height of the wall is specified by an array H of N positive integer

app.codility.com

 

 

Codility Lesson 8. Leader - Dominator

 - 가장 많이 발생한 숫자의 cnt가 '절반 보다 많이' 발생했을 시 Domiantor로 선정.

https://app.codility.com/demo/results/training77RP5D-XJY/

 

Test results - Codility

An array A consisting of N integers is given. The dominator of array A is the value that occurs in more than half of the elements of A. For example, consider array A such that A[0] = 3 A[1] = 4 A[2] = 3 A[3] = 2 A[4] = 3 A[5] = -1 A[6] = 3 A[7] = 3 The dom

app.codility.com

 

 

Codility Lesson 8. Leader - EquiLeader

 - Leader를 구하는 로직은 dominator에서 사용한 로직을 그대로 사용함.

 - dominator의 발생 횟수를 기준으로 left 발생횟수, right 발생횟수가 각 비교군에서 절반 보다 많이 발생했는지 만족하면 equiLeadr 로 카운트

https://app.codility.com/demo/results/training3W9URK-8GS/

 

Test results - Codility

A non-empty array A consisting of N integers is given. The leader of this array is the value that occurs in more than half of the elements of A. An equi leader is an index S such that 0 ≤ S < N − 1 and two sequences A[0], A[1], ..., A[S] and A[S + 1],

app.codility.com

 

 

Codility Lesson 9. Maximum slice problem - MaxProfit

 - 생각없이 for문 2번사용하여 각 원소별로 비교했다가 퍼포먼스를 만족하지 못함

 - 최소값을 지정하여 해당 값하고만 계산하도록 변경 후 퍼포먼스도 만족

https://app.codility.com/demo/results/trainingUNXQUA-R8G/

 

Test results - Codility

An array A consisting of N integers is given. It contains daily prices of a stock share for a period of N consecutive days. If a single share was bought on day P and sold on day Q, where 0 ≤ P ≤ Q < N, then the profit of such transaction is equal to A[

app.codility.com

 

 

Codility Lesson 9. Maximum slice problem - MaxSliceSum

 - maxNum 체크 먼저 수행해서 음수가 maxNum인 경우 해당 값 리턴

 - maxNum이 양수인 경우에만 로직을 수행해서 현재 인덱스까지의 핪(currentSum)과 현재 인덱스까지의 합 중 max 값(maxSliceSum) 중 큰 값을 리턴

https://app.codility.com/demo/results/training9DCYUY-ZT7/

 

Test results - Codility

A non-empty array A consisting of N integers is given. A pair of integers (P, Q), such that 0 ≤ P ≤ Q < N, is called a slice of array A. The sum of a slice (P, Q) is the total of A[P] + A[P+1] + ... + A[Q]. Write a function: class Solution { public int

app.codility.com

 

'Coding Test 준비 > codility' 카테고리의 다른 글

codility Lesson 풀어보기 6  (0) 2022.08.20
codility Lesson 풀어보기 4  (0) 2022.08.06
codility Lesson 풀어보기 3  (0) 2022.06.29
codility Lesson 풀어보기 2  (0) 2022.06.26
codility Lesson 풀어보기  (0) 2022.06.19