Skip to content

Instantly share code, notes, and snippets.

@dennislwm
Last active January 22, 2022 07:41
Show Gist options
  • Save dennislwm/b5b78619382be83094fbd31ab80acc34 to your computer and use it in GitHub Desktop.
Save dennislwm/b5b78619382be83094fbd31ab80acc34 to your computer and use it in GitHub Desktop.
singtel interview coding test find saddle point matrix.py
import sys
for line in sys.stdin:
numOpen = 0
numLength = 0
for c in line:
if c == '(':
numOpen += 1
elif c == ')':
numOpen -= 1
if numOpen < 0:
numOpen = 0
else:
numLength += 2
print(numLength)
import sys
def findSaddlePoint(mat, n):
for i in range(n):
min_row = int(mat[i][0]);
col_ind = 0;
for j in range(1, n):
if (min_row > int(mat[i][j])):
min_row = int(mat[i][j])
col_ind = j;
k = 0;
for k in range(n):
if (min_row < int(mat[k][col_ind])):
break;
k += 1;
if (k == n):
return min_row;
return 0;
row = 0
for line in sys.stdin:
if row == 0:
size = int(line)
square = [[0 for i in range(size)] for j in range(size)]
else:
arrLine = line.rstrip().split(",")
square[row-1] = arrLine
row += 1
if row == size + 1:
row = 0
result = findSaddlePoint(square, size)
if result == 0:
print("Invalid input")
else:
print(result)
#!/bin/bash
LOG_FILE="$1"
function request_per_day() {
declare -a day_array
while read line; do
day=$(echo "$line" | sed 's/.*\[//g;s/].*//g;s/:.*//g')
item=$(echo "$day" | sed 's/\//./g')
echo $item
day_array[$item]=1
if [[ ${day_array[*]} =~ "$item" ]]; then
day_array[$item]=$((day_array[$item] + 1))
else
day_array[$item]=1
fi
done < $LOG_FILE
#for day in ${!day_array[@]}; do echo ${day_array[$day]} $day; done | sort -rn | head -10
}
request_per_day
echo ""
function request_per_ip() {
declare ip_array
while read line; do
ip=$(echo $line | awk '{print $1}')
echo $ip
#if [[ -v ip_array[$ip] ]]; then
#if [[ ${ip_array[*]} =~ "$ip" ]]; then
# ip_array[$ip]=$((ip_array[$ip]+1))
#else
# ip_array[$ip]=1
#fi
done < $LOG_FILE
#for ip in ${!ip_array[@]}; do echo ${ip_array[$ip]} $ip; done | sort -rn | head -10
}
request_per_ip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment