Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View HemantNegi's full-sized avatar
💭
I may be slow to respond.

Hemant Negi HemantNegi

💭
I may be slow to respond.
View GitHub Profile
@HemantNegi
HemantNegi / select-next-ip.sql
Created September 26, 2019 05:58 — forked from rob-murray/select-next-ip.sql
Select the next available IP address using Postgres inet and cidr types
SELECT sub.ip FROM
(SELECT set_masklen(((generate_series(1,
(2 ^ (32 - masklen('10.10.100.0/24'::cidr)))::integer - 2) +
'10.10.100.0/24'::cidr)::inet), 32) as ip) AS sub
WHERE sub.ip NOT IN
(SELECT ip_address from ip_table)
AND sub.ip > set_masklen('10.10.100.0/24', 32)+10
AND sub.ip < set_masklen(broadcast('10.10.100.0/24')::inet, 32)-5;
@HemantNegi
HemantNegi / check_triangle.py
Created December 12, 2018 11:04
Given 3 sides of a triangle, check if triangle is possible
import math
import os
import random
import re
import sys
# Complete the triangle function below.
@HemantNegi
HemantNegi / delta_encode.py
Created December 12, 2018 11:03
Data encoding by difference
def delta_encode(array):
first = False
pre = None
diff = None
res = []
for i in array:
if not first:
res.append(i)
first = True
pre = i
@HemantNegi
HemantNegi / customer_service.py
Last active December 12, 2018 11:02
Customer service capacity
# Note: 1 case fails
import math
import os
import random
import re
import sys
@HemantNegi
HemantNegi / find_plagiarism.py
Last active November 26, 2018 06:52
find_plagiarism if a more than a given % of words match.
#
# Sample input for the program
# 7 60
# 201305641 2
# The quick brown fox jumps over the lazy dog
# the quick brown fox jumps over the lazy dog the
# 201305581 2
# The leisurely fox leisurely jumps over leisurely lazy dog
# the leisurely fox leisurely jumps over the leisurely lazy dog
# 201305051 2
@HemantNegi
HemantNegi / find_max_edges_count.py
Last active November 14, 2018 08:06
Find the maximum number of neighbors of an element in a matrix
# Given a matrix:
# 1,0,0,0,0
# 0,0,1,0,1
# 0,1,1,1,1
# 0,0,0,1,0
# 1,0,0,0,1
#
# find the maximum number of shaded cells (represented by 1) that share an edge with each other.
# eg. in the case above there are 7 cells that contains 1 and share an edge with each other
#
//Enter your code here. Read input from STDIN. Print output to STDOUT
//
//What is the execution order in the following program, and also the output ?
package main
import "fmt"
var WhatIsThe = AnswerToLife()
func AnswerToLife() int {
fmt.Println("asdfasdfasdf")
return 42
@HemantNegi
HemantNegi / atm_machine.py
Created October 24, 2018 13:02
implement an ATM machine.
# Enter your code here. Read input from STDIN. Print output to STDOUT
# DENOMINATIONS: 5 10 20 50
# BILLS: 4 3 1 1
# withdraw(75): return the number of bills/denomination (e.g.: one bill of 5, one bills of 20, one bill of 50)
NOTES = {
# 1: 10,
5: 4,
@HemantNegi
HemantNegi / max_path_sum_game.py
Created October 24, 2018 10:01
Find max path sum
# Complete the 'maxPathSum' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. 2D_INTEGER_ARRAY board
# 2. INTEGER p
# 3. INTEGER q
# NOTE use a dict to cache the results ro improve performance.
@HemantNegi
HemantNegi / special_elements.py
Created September 28, 2018 10:26
Special elements in a matrix
# Complete the countSpecialElements function below.
def countSpecialElements(matrix):
items = set()
for m, row in enumerate(matrix):
min_i, max_i, solution = min_max_in_list(row)
if not solution:
return -1
# add as row_col
items.add('%d_%d' % (m, min_i))
items.add('%d_%d' % (m, max_i))