Skip to content

Instantly share code, notes, and snippets.

@alexnikol
alexnikol / .py
Created August 10, 2020 07:51
Insert a Node at the Tail of a Linked List. Testing
# RESULT
node1 = SinglyLinkedListNode(1)
node2 = SinglyLinkedListNode(2)
node3 = SinglyLinkedListNode(3)
node1.next = node2
node2.next = node3
result = insertNodeAtTail(node1, 34)
@alexnikol
alexnikol / .py
Last active August 10, 2020 07:26
Insert a Node at the Tail of a Linked List. Realization
from linked_list import SinglyLinkedListNode
def insertNodeAtTail(head, data):
if head is None:
return SinglyLinkedListNode(data)
else:
current_node = head
while current_node.next is not None:
current_node = current_node.next
@alexnikol
alexnikol / .py
Created August 9, 2020 17:11
Print the Elements of a Linked List HackerRank Exercise. Testing
# RESULT
node1 = SinglyLinkedListNode(1)
node2 = SinglyLinkedListNode(2)
node3 = SinglyLinkedListNode(3)
node1.next = node2
node2.next = node3
printLinkedList(node1)
@alexnikol
alexnikol / .py
Last active August 9, 2020 17:10
Print the Elements of a Linked List HackerRank Exercise. Realization
from linked_list import SinglyLinkedListNode
def printLinkedList(head):
currentNode = head
while currentNode is not None:
print(currentNode.data)
currentNode = currentNode.next
@alexnikol
alexnikol / .py
Created August 9, 2020 16:57
Linked List Node realisation
"""Linked List Realization"""
class SinglyLinkedListNode:
def __init__(self, node_data):
self.data = node_data
self.next = None
@alexnikol
alexnikol / .swift
Last active July 13, 2020 18:00
Climbing the Leaderboard HackerRank - Medium Problem
func climbingLeaderboard(scores: [Int], alice: [Int]) -> [Int] {
func findClosestNumberInBoard(forNumber number: Int) -> Int { //Functions for searching the closest score in table
var left = 0 //with binary search
var right = scores.count - 1
var mid = 0
while left <= right {
mid = (left + right) / 2
if number == scores[mid] {
@alexnikol
alexnikol / .swift
Created June 30, 2020 05:44
PickingNumbers HackerRank - Solving
func pickingNumbers(a: [Int]) -> Int {
var repeatList = Array(repeating: 0, count: 100) //Generated list with 100 zeros
for i in 0..<a.count { //Count repeating of each item in input array
repeatList[a[i] - 1] += 1
}
var result = 0
for i in 0..<(repeatList.count - 1) {
let stepSum = repeatList[i] + repeatList[i + 1] //Sum of each item and next item
if stepSum > result { //The biggest met sum is our answer
result = stepSum
@alexnikol
alexnikol / .swift
Created June 29, 2020 03:53
Magic Square HackerRank - Solving
let magic1 = [[8, 1, 6], [3, 5, 7], [4, 9, 2]]
let magic2 = [[6, 1, 8], [7, 5, 3], [2, 9, 4]]
let magic3 = [[4, 9, 2], [3, 5, 7], [8, 1, 6]]
let magic4 = [[2, 9, 4], [7, 5, 3], [6, 1, 8]]
let magic5 = [[8, 3, 4], [1, 5, 9], [6, 7, 2]]
let magic6 = [[4, 3, 8], [9, 5, 1], [2, 7, 6]]
let magic7 = [[6, 7, 2], [1, 5, 9], [8, 3, 4]]
let magic8 = [[2, 7, 6], [9, 5, 1], [4, 3, 8]]
let posibleMagicSquares = [magic1, magic2, magic3, magic4, magic5, magic6, magic7, magic8]
var allPosibleAnswers: [Int] = []
@alexnikol
alexnikol / .swift
Last active June 29, 2020 03:51
Magic Square HackerRank - Problem
/*
Sample Input
*/
s =
4 9 2
3 5 7
8 1 5
/*
Sample Output - 1
@alexnikol
alexnikol / .swift
Created June 16, 2020 14:40
Cuphead-EarAndDrinkingTube
private func getDrinkingTubeShape() -> CAShapeLayer {
//Wraper Shape
let wrapPath = UIBezierPath()
wrapPath.move(to: CGPoint(x: 170, y: 145))
wrapPath.addLine(to: CGPoint(x: 125, y: 70))
wrapPath.addLine(to: CGPoint(x: 5, y: 110))
wrapPath.addQuadCurve(to: CGPoint(x: 35, y: 175),
controlPoint: CGPoint(x: -5, y: 160))
wrapPath.addQuadCurve(to: CGPoint(x: 95, y: 150),
controlPoint: CGPoint(x: 60, y: 165))