Skip to content

Instantly share code, notes, and snippets.

View NEbere's full-sized avatar
👩‍💻
...

Happiness Nwosu NEbere

👩‍💻
...
View GitHub Profile
// Codility Bbinary Gap Test
function solution($N) {
// write your code in PHP5.5
$binaryNumber = decbin($N); // binary conversion of number
$trimmed = trim($binaryNumber, 0); // trim to remove trailing zeros
$binaryGap = explode("1",$trimmed); // explode
$binaryCount = array_map('strlen', $binaryGap);
return max($binaryCount); // returns the longest binary gap
@NEbere
NEbere / rotate_array.py
Last active November 24, 2016 14:06
Given an array of integers and a number, , perform left rotations on the array.
# A left rotation operation on an array of size shifts each of the array's elements 1 unit to the left.
# For example, if 2 left rotations are performed on array [1,2,3,4,5], then the array would become [3,4,5,1,2]
#Given an array of n integers and a number,d , perform d left rotations on the array.
#Then print the updated array as a single line of space-separated integers.
def rotate(array, position):
#print
print (array[position:] + array[:position])
#or return
# Python2 solution for codility frog jump question
# https://codility.com/programmers/lessons/3-time_complexity/frog_jmp/
import math
def solution(X, Y, D):
# write your code in Python 2.7
source_and_destination_difference = Y - X
fixed_distance_jump = D
# Python3 solution to https://www.hackerrank.com/challenges/diagonal-difference/problem
# test data
first_array = [11, 2, 4]
second_array = [4, 5, 6]
third_array = [10, 8, -12]
sumArray = []
sumArray.append(first_array)
sumArray.append(second_array)
sumArray.append(third_array)
@NEbere
NEbere / findNonRepeatingChars.js
Created May 15, 2019 10:38
Given a string, find the non-repeating characters and return in form of an array
function findNonRepeatingChars(string) {
const stringArray = string.split('')
const nonrecurring = []
const resultObj = {}
for(let char of stringArray) {
if(!resultObj[char]) {
resultObj[char] = 1;
} else {
resultObj[char] += 1;
@NEbere
NEbere / sns-subscription.js
Created October 19, 2021 14:56
simple code to show SNS topic subscription, confirmation and notification handling via expressJS
const express = require('express')
const AWS = require("aws-sdk")
var bodyParser = require('body-parser')
const MessageValidator = require('sns-validator')
var jsonParser = bodyParser.json()
const config = {
"SNS_TOPIC_ARN": "",
"USER_ARN": "",
"USER_ACCESS_KEY_ID": "",
const express = require('express')
const AWS = require("aws-sdk")
var bodyParser = require('body-parser')
const MessageValidator = require('sns-validator')
const config = {
"SNS_TOPIC_ARN": "",
"USER_ARN": "",
"USER_ACCESS_KEY_ID": "",
"USER_SECRET_ACCESS_KEY": "",