Skip to content

Instantly share code, notes, and snippets.

@accakks
accakks / string_permutations.py
Created June 12, 2020 19:39
Print all permutations of a given string in Python
'''
Write a program to print all the permutations of a given string. For example:
Input : ABC
Output: ABC ACB BAC BCA CAB CBA
'''
from itertools import permutations
def print_permutations(s):
"""Prints permutations of a given string"""
@accakks
accakks / max_rob_amount.py
Created June 12, 2020 19:38
Dynamic solution to max rob amount problem
'''
You are a professional robber planning to rob houses along a street. Each house has
a certain amount of money stashed, the only constraint stopping you from robbing each
of them is that adjacent houses have security systems connected and it will
automatically contact the police if two adjacent houses were broken into on the
same night.
Given a list of non-negative integers representing the amount of money of each house,
determine the maximum amount of money you can rob tonight without alerting the
police.
'''
@accakks
accakks / amazing_substr.py
Created June 12, 2020 19:36
You are given a string S, you have to find all the ‘amazing’ substrings of S.
'''
You are given a string S, you have to find all the ‘amazing’ substrings of S.
‘Amazing’ substring is one that starts with a vowel (a,e,i,o,u,A,E,I,O,U)
Example:
Input: ABEC
Output: 6
Explanation: Amazing substrings of given string are :
1. A
2. AB
3. ABE
@accakks
accakks / README.md
Created June 12, 2020 19:35
Given two positive numbers X and Y. Find the maximum value integer A such that: a. A divides X i.e. X % A = 0 b. A and Y are co-prime i.e. gcd(A, Y) = 1

Problem Statement

Given two positive numbers X and Y. Find the maximum value integer A such that: a. A divides X i.e. X % A = 0 b. A and Y are co-prime i.e. gcd(A, Y) = 1 For example: X = 30
Y = 12 We return A = 5

@accakks
accakks / zip.py
Last active April 2, 2020 07:40
File Comparison
import requests
import urllib.request
from bs4 import BeautifulSoup
import zipfile, io
import os
url= 'http://staging.imgtranslate.com:9999/'
extension = ".zip"
r = requests.get(url)