Skip to content

Instantly share code, notes, and snippets.

View Roshankumar350's full-sized avatar
🎯
Focusing

Roshan Kumar Sah Roshankumar350

🎯
Focusing
View GitHub Profile
@Roshankumar350
Roshankumar350 / Cost_of_balloons.txt
Last active February 17, 2021 17:31
Cost of balloons : HackerEarth
// Write your code here
func solve() {
// know the cost of balloons
let costOfBallons = getArray(readLine()!)
// know the number of participants
let numberOfParticipant = Int(readLine()!)!
// some holder to capture who has solved the problem
var firstParticipantSolved = 0
@Roshankumar350
Roshankumar350 / ios-interview-resources.md
Created October 15, 2020 16:56 — forked from funmia/ios-interview-resources.md
General iOS, CS questions and interview prep resources.
func findIndexOf(targetSum sum: Int, in inputArray: [Int]) -> (Int,Int) {
//Output index
var indices: (Int,Int) = (-1, -1)
//count of input array
let inputArrayCount = inputArray.count
for (index, eachElement) in inputArray.enumerated() {
for sartIndex in index..<inputArrayCount {
if eachElement + inputArray[sartIndex] == sum {
func findIndexOf(targetSum sum: Int, in inputArray: [Int]) -> (Int,Int) {
// Output Indices
var indices: (Int,Int) = (-1, -1)
// hastable
var hashTable = [Int:Int]()
// enumerate it
for (index, value) in inputArray.enumerated() {
// check if hastable has complementry value (i.e index)
if let rightIndex = hashTable[value] {
indices.0 = index
@Roshankumar350
Roshankumar350 / NetworkExtension.swift
Last active February 28, 2021 10:07
Handy network extension
import Foundation
import Combine
// MARK: - Error
enum APIError: Error, LocalizedError {
case unKnown
case apiError(reason: String)
}
extension APIError {
func isvalidPasswordPolicy(_ password: String) -> Bool {
// Output
var isValidPasswordPolicy = false
// Get the component of each password policy
let components = password.components(separatedBy: CharacterSet.whitespaces)
// From 1st component get the lower and upper bound
let first = components[0].components(separatedBy: "-")
guard let lowerBound = Int(first.first ?? "0") else { return isValidPasswordPolicy }
func isvalidPasswordPolicy(_ password: String) -> Bool {
// Output
var isValidPasswordPolicy = false
// Get the component of each password policy
let components = password.components(separatedBy: CharacterSet.whitespaces)
// From 1st component get the lower and upper bound
let first = components[0].components(separatedBy: "-")
guard var lowerBound = Int(first.first ?? "0") else { return isValidPasswordPolicy }
// Problem: https://www.pramp.com/challenge/2WBx3Axln1t7JQ2jQq96
func findBusiestPeriod(data: [[Int]]) -> Int {
var timeStamp = 0
var busiest = -1
var currentBusiest = 0
let length = data.count
// MARK: Data Structure
public class BinaryTreeNode<Element: Comparable> {
weak var parent:BinaryTreeNode?
var leftNode:BinaryTreeNode?
var payload:Element
var rightNode:BinaryTreeNode?