Skip to content

Instantly share code, notes, and snippets.

View mkamranhamid's full-sized avatar

Kamran Hamid mkamranhamid

View GitHub Profile
@mkamranhamid
mkamranhamid / codility-frog-jump.js
Created June 5, 2020 13:34
Count minimal number of jumps from position X to Y.
// codility test prep questions
// A small frog wants to get to the other side of the road. The frog is currently located at position X
// and wants to get to a position greater than or equal to Y. The small frog always jumps a fixed distance, D.
// Count the minimal number of jumps that the small frog must perform to reach its target.
// Given X = 10, Y = 85, D = 30
// the function should return 3
function numberOfFrogJumps(x,y,d){
var distanceRequired = y-x;
var jumps = Math.ceil(distanceRequired/30)
@mkamranhamid
mkamranhamid / codility-array-pair.js
Created June 5, 2020 13:14
Find value that occurs in odd number of elements.
// codility test prep questions
// For example, in array A such that:
// A[0] = 9 A[1] = 3 A[2] = 9 A[3] = 3 A[4] = 9 A[5] = 7 A[6] = 9
// the elements at indexes 0, 2 and 4 have value 9,
// the elements at indexes 1 and 3 have value 3,
// the element at index 5 has value 7 and is unpaired.
function findPairs(arr){
var hash = {}
arr.map((num)=>{
@mkamranhamid
mkamranhamid / codility-sequence.js
Created June 5, 2020 12:59
Find longest sequence of zeros in binary representation of an integer.
// codility test prep questions
// For example, number 9 has binary representation 1001 and contains a binary gap of length 2.
// The number 529 has binary representation 1000010001 and contains two binary gaps: one of length
// 4 and one of length 3. The number 20 has binary representation 10100 and contains one binary gap of length 1.
// The number 15 has binary representation 1111 and has no binary gaps. The number 32 has binary representation
// 100000 and has no binary gaps.
function findFirstNumberOfZeroes(num){
var binary = num.toString(2);
var numberOfZeros = 0;
@mkamranhamid
mkamranhamid / mergeArray.js
Created November 3, 2019 13:47
this problem covers the basic understanding of how we can merge the two arrays if there values overlaps
// Input: [[1,3],[2,6],[8,10],[15,18]];
// Output: [[1,6],[8,10],[15,18]];
// Explaination: Since intervals [1,3] and [2, 6] overlaps, merge them into [1, 6].
var arr = [[1,3],[2,6],[8,10],[15,18]];
var newArr = [];
var index = 0;
while (index <= arr.length-1) {
var currentVal = arr[index];
var nextVal = arr[index+1] || 0;
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
googlePlayServicesVersion = "15.0.1" // default: "+"
firebaseVersion = "+" // default: "+"
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
info Starting JS server...
info Building and installing the app on the device (cd android && gradlew.bat app:installDebug)...
> Configure project :app
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
> Configure project :react-native-firebase
react-native-firebase: using React Native prebuilt binary from D:\React-Native\...\node_modules\react-native\android
@mkamranhamid
mkamranhamid / findKthLargestNumber.py
Last active December 15, 2019 09:37
a function to get the K'th largest value in python
# For an unsorted array/list of n integers find the k-th largest element, where k <= n-1.
# Example: For A = [5,9,27,3,28,18,45] and k=4 the output will be 18.
def findKthLargestNumber(arr, n=3):
k= n-1 #
print(arr) # previous state
arr.sort(reverse=True) # {reverse=True} will make the sort to work in descending order
print(arr) # after sort in descending order
print(arr[k]) # fetch the kth value
findKthLargestNumber([5,9,27,3,28,18,45] ,4)
@mkamranhamid
mkamranhamid / index.html
Created June 22, 2016 17:30 — forked from puf/index.html
Zero to App: Develop with Firebase (for Web - Google I/O 2016)
<html>
<head>
<script src="https://www.gstatic.com/firebasejs/3.0.0/firebase.js"></script>
<title>ZeroToApp</title>
<style>
#messages { width: 40em; border: 1px solid grey; min-height: 20em; }
#messages img { max-width: 240px; max-height: 160px; display: block; }
#header { position: fixed; top: 0; background-color: white; }
.push { margin-bottom: 2em; }
@keyframes yellow-fade { 0% {background: #f2f2b8;} 100% {background: none;} }