Computer Engineering16 반복되지 않는 첫 번째 문자 찾기 Q. 문자열에서 처음으로 반복되지 않는ㄴ 문자를 찾아내는 효율적인 함수를 작성하라. 예를 들어 "total"에서 처음으로 등장하는 반복되지 않는 문자는 'o'이며, "teeter"에서 처음으로 등장하는 반복되지 않는 문자는 'r'이다. 자신이 작성한 알고리즘의 효율에 대해 논하라. A.1) 가장 쉬운 방법은 특정 문자를 그 문자열에 있는 다른 모든 문자와 비교하여 그 문자가 반복되는지 아는 방법이다. 하지만 이같은 풀이는 실행시간이 오래걸린다. 문자열 길이가 n이라면 최악의 경우 n개의 문자들을 모두 n번씩 비교해야 한다.(마치 버블 정렬같이) 즉, 시간복잡도 O(n^2)을 가진다. 그렇다면 더 효과적으로 해결할 수 있는 방법은 없을까? 2) 이 문제는 데이터에 대한 효율적인 검색을 할 수 있는지 유도하.. 2014. 11. 18. Codility - ArrayInversionCount https://codility.com/demo/results/demoBD476U-K6K/ Task descriptionA zero-indexed array A consisting of N integers is given. An inversionis a pair of indexes (P, Q) such that P < Q and A[Q] < A[P].Write a function:class Solution { public int solution(int[] A); }that computes the number of inversions in A, or returns −1 if it exceeds 1,000,000,000.Assume that:N is an integer within the range [0..1.. 2014. 10. 26. Codility - Equi Leader https://codility.com/demo/results/demoV3FC6D-GGH/ Task descriptionA non-empty zero-indexed 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], A[S + 2], ..., A[N − 1] have leaders of the same value.For example, g.. 2014. 10. 26. Codility - Domains https://codility.com/demo/results/demoHKWW2G-8TM/Task descriptionA zero-indexed array A consisting of N integers is given. Thedominator of array A is the value that occurs in more than half of the elements of A.For example, consider array A such thatA[0] = 3 A[1] = 4 A[2] = 3 A[3] = 2 A[4] = 3 A[5] = -1 A[6] = 3 A[7] = 3The dominator of A is 3 because it occurs in 5 out of 8 elements of A (namel.. 2014. 10. 26. Codility - Fish https://codility.com/demo/results/demoV445T8-FZN/ Task descriptionYou are given two non-empty zero-indexed arrays A and B consisting of N integers. Arrays A and B represent N voracious fish in a river, ordered downstream along the flow of the river.The fish are numbered from 0 to N − 1. If P and Q are two fish and P < Q, then fish P is initially upstream of fish Q. Initially, each fish has a uni.. 2014. 10. 26. Codility - StoneWall https://codility.com/demo/results/demoFHGPX8-MAF/ Task descriptionSolution to this task can be found at our blog.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 a zero-indexed array H of N positive integers. H[I] is the he.. 2014. 10. 25. 이전 1 2 3 다음