Skip to main content

All Questions

7 votes
4 answers
7k views

Find the shortest whole repetitive substring

I'm working on a problem to find wholly repeated shortest substring of a given string, and if no match, return length of the string. My major idea is using a Trie ...
Lin Ma's user avatar
  • 3,493
5 votes
4 answers
948 views

Decrease Computation Time for Python Tic-Tac-Toe Minimax Algorithm

Background I am currently participating in a tic-tac-toe coding challenge. During their move, each participant is given the board state and their team, X or O. The blank board is: ...
DapperDuck's user avatar
4 votes
4 answers
21k views

Use Python to determine the repeating pattern in a string

I am writing an algorithm to count the number of times a substring repeats itself. The string is between 1-200 characters ranging from letters a-z. There should be no left overs at the end of the ...
Jake Steele's user avatar
6 votes
4 answers
23k views

Plus Minus in Python

You're given an array containing integer values. You need to print the fraction of count of positive numbers, negative numbers and zeroes to the total numbers. Print the value of the fractions ...
CodeYogi's user avatar
  • 5,137
14 votes
4 answers
2k views

Codechef: Prime Number Generator

Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers! Input The input begins with the number t of test cases ...
Subham Goyal's user avatar
7 votes
4 answers
7k views

Buy once and sell once for maximum profit

Suppose we have stock price history, and we are allowed to buy only once and sell only once. The problem is to find the maximum profit we can make. Here is my code that I tested for basic test cases. ...
Lin Ma's user avatar
  • 3,493
7 votes
4 answers
1k views

Solving jumbled letters using a given dictionary

Given a dictionary, a method to do lookup in dictionary and a M x N board where every cell has one character. Find all possible words that can be formed by a sequence of adjacent characters. Example: ...
katty's user avatar
  • 615
4 votes
2 answers
4k views

Getting the unique factors of a number recursively

I have written the below code to get the unique factors. Please offer suggestions for better results. ...
deep's user avatar
  • 143
6 votes
4 answers
2k views

Kadane's Algorithm for 2D array with known boundaries

I asked this question first on StackOverflow but I didn't get an answer and was advised to try here too. So here we go. I have implemented Kadane's algorithm for a 2D array in Python 2 with known ...
ChrisG's user avatar
  • 163
3 votes
3 answers
6k views

Finding the longest palindromic substring

I have the following code that works correctly. I am wondering if there is a simpler way to go about implementing my solution and/or if there is anything that looks non-standard in my code. If anyone ...
Calvin Ellington's user avatar
5 votes
3 answers
14k views

Diagonal difference

Given You are given a square matrix of size \$N×N\$. Calculate the absolute difference of the sums across the two main diagonals. Input Format The first line contains a single integer N. The next ...
CodeYogi's user avatar
  • 5,137
10 votes
4 answers
14k views

Consolidate list of ranges that overlap

I wanted to implemented an algorithm in Python 2.4 (so the odd construction for the conditional assignment) where given a list of ranges, the function returns another list with all ranges that overlap ...
pedromarce's user avatar
6 votes
5 answers
4k views

1D Peak Finder Algorithm

I'm reviewing MIT Introduction to Algorithm lectures/exercises and am trying to implement a one dimensional peak finder algorithm. I've got a working copy but it's a bit messy and I've had to put ...
openingceremony's user avatar
3 votes
3 answers
598 views

Binary Insert Method - handling edge cases

I've created a function that uses binary search to insert an element into an array (similar to this question). I haven't benchmarked it, but based on my knowledge it should get \$O(1)\$ in the best ...
sotrh's user avatar
  • 195
8 votes
4 answers
10k views

"Largest power of two less than N" in Python

...
CodeYogi's user avatar
  • 5,137

15 30 50 per page
1
2 3 4 5
11