This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. a) Для n^2. 1000 - секунда. k - кількість операцій. Для Time(n) = k * f(n). | |
Підставимо, 1секунда = k * 1000^2(бо у нас n ^2). 1 = k * 1 000 000, k = 1 / 1 000 000 = 10^-6. | |
Тепер ми знаємо скільки операцій для 1000, підставляємо - 10^-6 * 10 000^2 = 100 секунд. | |
б) для цього прикладу робимо те саме тільки підставляємо n log n замість n^2, | |
log2 1000 = 10, 1 = k * 1000 * 10 = 10^-4, получається k = 10^-4. | |
рахуємо для 10 000 (скільки треба відсортувати) - 10^-4(це наше k) * 10 000 * 13.2827(13.2827 ~~ log2 10 000) = 13.2827 sec. | |
2. Скільки операцій зробить ноутбук за рік якщо постійно працює? | |
Треба дізнатись клок спід проца + скільки секунд в році. У мене apple mac book pro на процесорі M1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task 4 | |
В таскі 4 3 питання, постараюсь дати відповідь на кожне з них. | |
1. Тут(функція get_next_diff) в while ми біжимо по усім симвалам ітеративно і перевіряємо чи вони рівні | |
current_index == next_index. Ну і плюс поки рядок не закінчиться (n). | |
В найгіршому випадку буде таке що усі символи однакові, напиклад 'yyyy' - получається пробіжим | |
по всім і буде O(n). Але може пощастити і буде таке що наступний символ інший - тоді складність O(1). | |
Але питання найгірший кейс - відповідь O(n). | |
2. В найгіршому кейсі функція get_next_diff викличиться N разів якщо у нас усі символи різні, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task 3. | |
Programming language ruby/python. | |
1. Paginated get - complexity O(n). | |
Reading params - O(1). | |
Calculate indexes - both strings are O(1). | |
File open - O(1). | |
Читання построчно попередніх засторених айтемів - O(n) (читаємо усі 1 за 1 з верху вниз). | |
Return результату O(1). | |
2. Post - отримання params data - O(1), | |
file open - O(1). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task 1. | |
a. for(int i = 5; i < n/2; i += 5) | |
api() | |
i = 5 + 5k | |
5k < n / 2 - 5 | |
k < (n/2) - 5 / 5 | |
k < n - 10 / 10 | |
O(n) | |
b. for (int i = n; i > 1; i /= 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from collections import Counter | |
from typing import List | |
# simple solution(accepted by leetcode, beat 52%) | |
# Time - O(n), Space - O(n) | |
def majorityElement(nums: List[int]) -> int: | |
# O(n) | |
counter = Counter(nums) | |
# O(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
$("#projectButton").click(function () { | |
$('#listOfNames').empty(); | |
$.post("/get_last_ten_projects_names", function (data) { | |
$.each(data['projects'], function (index, value) { | |
$('#listOfNames').append('<li>' + value + '</li>'); | |
}); | |
}); | |
}); | |
$("select#myAwesomeSelect").change(function(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calc(n1, op, n2, n3) { | |
switch (op) { | |
case '+': | |
return ((n1 + n2) === n3); | |
case '-': | |
return ((n1 - n2) === n3); | |
case '*': | |
return ((n1 * n2) === n3); | |
case '/': | |
if (n2 === 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1.2 Makovskyi | |
function search(needle, haystack) { | |
var i = 0; | |
var valueSearching = false; | |
if (typeof haystack === 'object') { | |
if (Array.isArray(haystack)) { | |
for (; i < haystack.length; i++) { | |
if (search(needle, haystack[i])) { | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function highOrder(n) { | |
return (Math.pow(10, n) - 1); | |
} | |
function lowOrder(n) { | |
return (1 + Math.pow(10, n - 1)); | |
} | |
function isPrimary(i) { | |
var j = 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mostSignificantDigit (n) { | |
var maxNumber = Math.pow(10, n) - 1; | |
return maxNumber; | |
} | |
function _minNumber (n) { | |
var minNumber = 1 + Math.pow(10, n - 1); | |
return minNumber; | |
} | |
function isPrimary (i) { | |
for ( var j = 2; j < Math.sqrt(i); j++) { |
NewerOlder