Reversing a number

I was working through a programming challenge I found on Reddit and it seemed easy enough: Find all numbers less than \$10^n\$ where the number and its reverse (the reverse of \$123\$ is \$321\$) are both divisible by \$7\$ and then sum them all together. def challenge_229(power): numbers = [] for x in range(0, 10**power, … Read more

HackerRank Implement Queue using two stacks Solution

Challenge Problem Statement – Implement a Queue using two Stacks I implemented dequeue() in O(1) at the cost of enqueue() in O(n) #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <stack> using namespace std; struct Queue{ stack<int> s1,s2; int dequeue(){ int x =; s1.pop(); return x; } void peek(){ cout<<<<“\n”; … Read more

Finding area and perimeter of rectangles and circles that are instance of interface region

The missing code in task 1 were the methodsarea(), perimeter() and toString(). In task 2 I know that using built in collection such as Arraylist would be efficient and simpler,So any new different idea and implementation are appreciated. Make the classes Circle and Rectangle complete: write the missing code. A static method selectRectangle accepts an … Read more

Parsing n lines to count vowels – HackerEarth

I have written a haskell program for the following ‘Code Monk’ Challenge at HackerEarth. Here is the challenge description. Basically, we are looking for the number of vowels in a string. The first input n is the number of string to parse, followed by n number of random strings. And here is my implementation: import … Read more

Find next bigger number with same combination of digits

Please review my code for a puzzle to find next bigger number with same combination of digits. so if the number is 156432 the next bigger number is 162345 I wrote a program which is as follows, // converts a number // to an number array // i.e. 13452 = [1,3,4,5,2] var convertToNumArray = function(num){ … Read more

KQuery SPOJ problem, using merge sort segment tree

Problem : KQUERY Summary: For each query consisting of \$(i, j, k)\$, return the number of elements greater than \$k\$ in the subsequence \$a_i, a_{i+1}, …, a_j\$. My code has complexity of \$O(n\log^2{n})\$. I am only interested in segment tree based solution of Kquery. Please let me know why am I getting TLE using merge … Read more

Create all combinations of length N from a given alphabet (2)

I implemented this challenge in Java before but performance was not the best so I decided to implement this in C++ to compare the two. The code works and performance is indeed much better than in the Java version. However I am unsure about the quality of this code. I am still not overly familiar … Read more

Project Euler Problem 12 in Python 3 (Find triangle number with 500 divisors)

I am doing Project Euler, and 12 is the one that takes significantly longer then everything else. Here is my code: # The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be # 1 + 2 + 3 + 4 + 5 + 6 + 7 … Read more

Valid Alphanumeric Palindrome

Valid Alphanumeric Palindrome Problem (from Leetcode) Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, A man, a plan, a canal: Panama is a palindrome but race a car is not a palindrome. Discussion My approach was the following: Start with first and last characters of … Read more