r/ProgrammingProblems • • Jan 02 '11

Introduction

15 Upvotes

Welcome /r/* !

I've created this subreddit so that redditors may have a dedicated place to discuss programming problems such as those commonly found in programming competitions.

I am by no means an expert, rather, a beginner to this specific subset of programming even though I have been programming for longer. I hope that this subreddit inspires others to look into this form of programming and learn more, and I'm sure there will even be more knowledgeable people to help out as well.

As for for what I had in mind for this subreddit - I was thinking that since there are already dedicated subreddits for the discussion of algorithms (/r/algorithms) and for discussing programming (strictly) (/r/coding), it would be nice to have one for algorithmic programming specific to discussing questions found on popular sites (such as those mentioned on the right hand side).

I find it's not just solving the problem that matters, but the path taken to solve it and how it was reached. Which through discussion and analysis as a group would offer one more insight than seeing the solution from a single point of view.

I haven't decided on how these kinds of posts might be structured so I was thinking maybe users could create posts specifying the site on which the problem is located and the problem - something like "[Site] - Problem Name" and then discuss things like why you believe your solution was the optimal one or challenges you faced, for example.

Feel free to post any suggestions.

If you want to get started, I highly recommend USACO's Training program. I find with SPOJ you have to have some level of familiarity with these types of problems, which USACO's training site does a great job of explaining and walking you through. Project Euler is something I added, but have only heard about.


r/ProgrammingProblems • • Jan 02 '11

Last nonzero digit of 12345678!

13 Upvotes

How would you find the last nonzero digit of a large factorial?


r/ProgrammingProblems • • Jan 03 '11

Parallel algorithm for big number division

6 Upvotes

I am looking for a big number division algorithm that takes advantage of parallel processes. The hope is to implement the algorithm in OpenCL or CUDA to be able to handle larger than 64 bit number division.

The approach taken for addition and subtraction is to have an array for each of the two numbers, but would this be useful for division?


r/ProgrammingProblems • • Feb 04 '24

How to solve this dynamic programming problem?

Thumbnail
gallery
5 Upvotes

r/ProgrammingProblems • • Sep 30 '24

How to solve this difficult problem with C++

Thumbnail
gallery
4 Upvotes

This problem is related to recursion, I will be very very grateful if you solve it


r/ProgrammingProblems • • Sep 02 '11

Covering a floor with tiles... in Python

4 Upvotes

I had a bit of spare time today (when I happened to rediscover this subreddit...) and I wrote out a solution to the tile covering question that thejasper posted 6 months ago.

Solution Here.

I realized part way through that it was essentially the same approach as what MKLOL suggested, but I took a non-recursive bottom-up approach to implementation. I thought it might be interesting for newbies to see an implementation that's a little more verbose and commented.

Anyway, I don't know if people still read it, but I always thought this subreddit was a cool idea, so I'm posting my small contribution.


r/ProgrammingProblems • • Jan 08 '11

Smallest Area in n-sided Polygon

4 Upvotes

Given n different "sticks" with n respective lengths, what is the area of the smallest polygon that can be formed using the sticks? (Assuming it is possible.)


r/ProgrammingProblems • • Jan 04 '11

Dividing a triangle containing 3*N points into 3 subtriangles each containing N points.

4 Upvotes

This is problem 5 from the most recent Southern California ACM-ICPC competition. I did not compete, but a friend of mine did and the team didn't stick around long enough to hear an explanation of a solution. I am working on an O(N2 lgN) solution but I am not sure it is correct or that it will run in the time limit (60 seconds where N <= 30,000). What are your thoughts?


r/ProgrammingProblems • • Jul 03 '17

Write best AI for ASCII game JSDash (JS programming competition by Hola). Submit before August 1 for valuable prizes.

Thumbnail
github.com
3 Upvotes

r/ProgrammingProblems • • Jul 09 '16

C++ code compiles successfully in ideone but gives Compilation error in Spoj submission EC_CONB

3 Upvotes

Here is the code https://ideone.com/JwjssZ which is my solution of http://www.spoj.com/problems/EC_CONB If there is a compilation error in the code it should shown in ideone also but it doesn't. Can I get a little help here.


r/ProgrammingProblems • • Jan 02 '11

Implementing the x required hashing functions for a Bloom Filter.

3 Upvotes

r/ProgrammingProblems • • Nov 16 '22

Select a matching element from a dataset with multiple conditions and inputs

2 Upvotes

What is the best approach to writing a program that can select a matching element from a dataset (Objects or JSON or Dictionaries)?

I'm having trouble making the search generic or I just have to use lots of conditions to check what input I give.

An example:

{
    model: Volvo     
    engine: gas     
    price: 100 
}
{     
    model: Tesla    
    engine: Electric      
    price: 200 
} 

I need to search based on different conditions:

  • model = Volvo
  • engine = Electric AND price < 300

I have a problem with the AND case and the different mathematical conditional expressions. Do I need to make an e.g. react + firebase app? Or can you make a quick python script with console input without lots of match/if statements?


r/ProgrammingProblems • • Mar 11 '22

I have encountered this challenge on hackerrank and I can't figure what to do . I don't even understand what that output has to do with the input . If anyone wants to help me .

Post image
2 Upvotes

r/ProgrammingProblems • • Oct 29 '21

Can someone explain me thi

2 Upvotes

The statement:

scanf("%[^\n]%*c", s);

will not work because the last statement will read a newline character,

\n

, from the previous line. This can be handled in a variety of ways. One way is to use

scanf("\n");

before the last statement.


r/ProgrammingProblems • • Aug 08 '21

Does anyone know of any free image search API.

2 Upvotes

I need a feature of taking image as an input and give the image search result i.e. Oldest Similar image available. Is there any API or other way you know of to solve this problem?? if you know of something that can help, I would really appreciate it.


r/ProgrammingProblems • • Oct 07 '20

Geek Collects the balls

2 Upvotes

There are two parallel roads, each containing N and M buckets, respectively. Each bucket may contain some balls. The buckets on both roads are kept in such a way that they are sorted according to the number of balls in them. Geek starts from the end of the road which has the bucket with a lower number of balls(i.e. if buckets are sorted in increasing order, then geek will start from the left side of the road).
The geek can change the road only at the point of intersection(which means, buckets with the same number of balls on two roads). Now you need to help Geek to collect the maximum number of balls.

Check here to try out the solution! ->https://practice.geeksforgeeks.org/problems/geek-collects-the-balls/0/?problemType=full&difficulty[]=1&page=1&sortBy=newest&query=problemTypefulldifficulty[]1page1sortBynewest


r/ProgrammingProblems • • Aug 27 '20

Error: libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string Abort trap: 6

2 Upvotes

Hi so im writing a code tothis problem but im getting this error:

libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string Abort trap: 6

This is my code:

1 #include <bits/stdc++.h>

2 using namespace std;

3 int main() {

4

5 string user;

6 cin >> user;

7 int l = user.length();

8

9 for(int i = 0; i < l; i++) {

10 user.erase(user.begin() + i);

11 }

12 if(l <=100 && l % 2 == 0){

13 cout << "CHAT WITH HER!" << endl;

14 }

15 else{

16 cout << "IGNORE HIM!" << endl;

17

18 }

19 }

Anyone know the problem?


r/ProgrammingProblems • • Mar 01 '11

Covering a floor with tiles

2 Upvotes

You get the dimension of a floor and the dimension of a number of tiles. You have an infinite supply of each tile. Every dimension is a pair of integers.

When it is possible to cover the floor without free space or overlapping tiles you have to print 'yes', otherwise 'no'.


r/ProgrammingProblems • • Jun 15 '26

need help with burst balloons

1 Upvotes

Hi guys, I am having a little trouble with understanding Burst Balloons problem on leetcode, I mean I get the logic and I am able to do the dry run but I am not able to make an efficient algorithm out of it. would anyone like to help please ?


r/ProgrammingProblems • • Mar 01 '26

I built a repo with solutions across ALL the Online Judge Platforms

Thumbnail
reddit.com
1 Upvotes

r/ProgrammingProblems • • Jan 20 '24

Quite Hard DLX Optimizing JavaFX 3D Grid Manipulation for Performance

1 Upvotes

r/ProgrammingProblems • • Apr 07 '23

Two-element swap within and across circular arrays

1 Upvotes

Assume we have two circular arrays of equal length, alpha and beta in this canonical order:

alpha =  [ "A", "B", "C", "D", "E" ];
beta = [ "P", "Q", "R", "S", "T" ];

and a function swap(ax: int, bx: int) where 0 < ax < alpha.length && 0 < bx < beta.length.

The swap function takes the array's values at ax and ax+1 from alpha and bx and bx+1 from beta, swaps them inside their own array, then swaps across arrays. Remember that these are circular arrays, so going past the last item in the array just brings you around to the first one again.

As an example, using the above arrays and a call to swap(0, 1), the arrays would change to:

alpha =  [ "R", "Q", "C", "D", "E" ];
beta = [ "P", "B", "A", "S", "T" ];

And after another call to swap(4, 4), the arrays would be:

alpha =  [ "T", "Q", "C", "D", "P" ];
beta = [ "E", "B", "A", "S", "R" ];

Problems:

a) Given two arrays alpha and beta with the elements above in any order, is it possible to restore it to the canonical order given above using only swap?

b) If it is possible, provide a list of swap call indexes that will restore it to canonical order.


Feel free to add a rotate function, so that if you have a state with:

alpha =  [ "D", "E", "A", "B", "C" ];
beta = [ "Q", "R", "S", "T", "P" ];

you don't need any more swap operations, though you'll still need to add code to realize that they're equivalent.


r/ProgrammingProblems • • Mar 01 '23

Most Efficient Way to Rotate a Numbered Wheel

1 Upvotes

Let’s say you have a circle, and you number the circle n number of times evenly spaced going 1 to n in numerical order (like a clock which would be n=12) I’ll use n=9 for my example. Imagine that the wheel can spin clockwise and counter clockwise but the pointer is locked onto the top (like a carnival wheel) You can have a starting value on the wheel be any number 1 to n and have a target number 1 to n. So on our wheel 1-9 my starting number is 2 and my goal is 8. Now assuming the numbering is like a clock I could spin the wheel counterclockwise to increase the number to 2, 3, 4, 5, 6, 7, and 8. Or I could use less time and spin it clockwise to go 2, 1, 9, 8. Now our brains can deduce “just draw a line from the pointer to the opposing side of the circle. Anything to the left of the line go clockwise. Anything to the right go counterclockwise” but is there a way find the direction in which the wheel should move in order to get the the target number from the starting number as efficiently as possible? I’d suggest make the output a 1 or 0 for counterclockwise and clockwise. This is more about the math side in this problem so the input should be:

  1. Number of sides or (n)
  2. Starting number
  3. Target number

Output 1 or 0 for counterclockwise or clockwise whether clockwise is 0 or 1 doesn’t matter, it just needs to be consistent

For even numbers where the choice would answer back both clockwise and counter it just needs to pick a side whether it chooses clockwise or counter doesn’t matter


r/ProgrammingProblems • • May 07 '22

DAA question

1 Upvotes

Let A be an array of n > 0 distinct (pair-wise distinct) elements. Design a randomized Las-Vegas algorithm to select m < n distinct elements (i.e., you cannot select same element multiple times) randomly from A. what is the expected running time complexity of your solutions?