Post
#1
|
|
|
Grupa: Zarejestrowani Postów: 144 Pomógł: 0 Dołączył: 15.09.2016 Skąd: Warszawa Ostrzeżenie: (0%)
|
Włączyłem pierwszy lepszy test na codility.com i głowa boli. Czy to dla was bułka z masłem? przez dwie godziny nie udało mi się napisać algorytmu na papierze, nie mówiąc o php. Coś takiego ma rozwiązać kandydat na JuniorPHP?
https://codility.com/programmers/challenges/titanium2016/ Cytat A bracket sequence is considered to be a valid bracket expression if any of the following conditions is true:
it is empty; it has the form "(U)" where U is a valid bracket sequence; it has the form "VW" where V and W are valid bracket sequences. For example, the sequence "(())()" is a valid bracket expression, but "((())(()" is not. You are given a sequence of brackets S and you are allowed to rotate some of them. Bracket rotation means picking a single bracket and changing it into its opposite form (i.e. an opening bracket can be changed into a closing bracket and vice versa). The goal is to find the longest slice (contiguous substring) of S that forms a valid bracket sequence using at most K bracket rotations. Write a function: class Solution { public int solution(String S, int K); } that, given a string S consisting of N brackets and an integer K, returns the length of the maximum slice of S that can be transformed into a valid bracket sequence by performing at most K bracket rotations. For example, given S = ")()()(" and K = 3, you can rotate the first and last brackets to get "(()())", which is a valid bracket sequence, so the function should return 6 (notice that you need to perform only two rotations in this instance, though). Given S = ")))(((" and K = 2, you can rotate the second and fifth brackets to get ")()()(", which has a substring "()()" that is a valid bracket sequence, so the function should return 4. Given S = ")))(((" and K = 0, you can't rotate any brackets, and since there is no valid bracket sequence with a positive length in string S, the function should return 0. Assume that: string S contains only brackets: '(' or ')'; N is an integer within the range [1..30,000]; K is an integer within the range [0..N]. Complexity: expected worst-case time complexity is O(N); expected worst-case space complexity is O(N) (not counting the storage required for input arguments). Ten post edytował porzeczki 10.11.2016, 18:10:57 |
|
|
|
![]() |
Post
#2
|
|
|
Grupa: Zarejestrowani Postów: 1 707 Pomógł: 266 Dołączył: 3.07.2012 Skąd: Poznań Ostrzeżenie: (0%)
|
Na pierwszy rzut oka to zadanie jest bardzo trudne, ale musi być łatwe rozwiązanie, skoro oczekują O(n). Najtrudniejsze jest to, że trzeba znaleźć długość sekwencji, ale nie jest powiedziane, że musi być to sekwencja od początku S.
Nie lubię takich zadań, bo mnie przytłaczają (IMG:style_emoticons/default/biggrin.gif) |
|
|
|
porzeczki czy jestem za głupi by programować? 10.11.2016, 01:35:51
porzeczki Odetchnąłem, myślałem, że te testy są by odsiać gł... 10.11.2016, 02:54:56
Pilsener Ja z takich testów jeszcze nie dostałem chyba więc... 10.11.2016, 09:40:13
memory Cytatkilkuset ?
To przez 20 lat musiałbyś co miesi... 10.11.2016, 11:45:22 
SmokAnalog Cytat(memory @ 10.11.2016, 11:45:22 )... 10.11.2016, 12:45:12
porzeczki https://codility.com/demo/results/trainingZXD8PR-U... 10.11.2016, 14:13:24
SmokAnalog Codility sprawdza Twój kod testami. Mają zestawy d... 10.11.2016, 14:49:28
porzeczki no ja rozumiem, ale dlaczego w tym konkretnym przy... 10.11.2016, 15:07:49
SmokAnalog Nie do końca rozumiem Twoje pytanie. Widzi 6, bo t... 10.11.2016, 15:23:33
porzeczki oszczerstwo i potwarz. Jak 6 skoro 4. (chyba jedna... 10.11.2016, 15:28:47 
SmokAnalog Cytat(porzeczki @ 10.11.2016, 15:28:4... 10.11.2016, 15:41:53
porzeczki no ja wiem, że algorytm.
Dobra mniejsza z tym. 10.11.2016, 15:47:12
SmokAnalog Twój bug polega na tym, że $sequence resetuje... 10.11.2016, 15:49:33
porzeczki no tak 10.11.2016, 15:52:35
SmokAnalog No to masz odpowiedź 10.11.2016, 15:53:43
porzeczki jest 100%, było 66%
czyli 66% dla mnie 34% dla ci... 10.11.2016, 15:55:56 
aniolekx wasz team - poniewaz zdobyl 100% ;D
Cytat(porzecz... 10.11.2016, 16:49:59
Pilsener CytatAczkolwiek ja też nie wierzę w te kilkaset, p... 14.11.2016, 08:42:53
nospor @porzeczki drobna uwaga co do
if (strpos($st... 14.11.2016, 10:59:07 
SmokAnalog Cytat(nospor @ 14.11.2016, 10:59:07 )... 14.11.2016, 13:14:02
nospor Ah, ich znow ta klotnia. Nie, nie prawie. Wg potrz... 14.11.2016, 13:18:13 
SmokAnalog Cytat(nospor @ 14.11.2016, 13:18:13 )... 14.11.2016, 16:42:47
daro0 No cóż:
https://codility.com/demo/results/training... 14.11.2016, 16:06:58
nospor Czy rozwiazywanie tych testow polega na kopiowaniu... 14.11.2016, 16:09:08
nospor Ano nie musimy Z jednym chyba sie jednak zgodzisz... 14.11.2016, 16:43:18
SmokAnalog Tak, zgadzam się z tym, ale uważam, że walenie na ... 14.11.2016, 17:01:08
nospor Cytatale uważam, że walenie na ślepo == jest o wie... 14.11.2016, 17:08:58
viking Dobrze jeśli piszemy w PHP7 (albo 7.1 ) z dokładn... 14.11.2016, 17:11:41
nasty A ja uwazam ze jesli tego nie umiesz rozwiazac to ... 30.04.2017, 14:40:18 ![]() ![]() |
|
Aktualny czas: 31.12.2025 - 19:37 |