Programming Logic Concepts

So I am a year into Java and learnt a lot, but the problem is that I don't know most of the programming concepts or algorithms (as I focused on different stuff like Minecraft dev, Android, JavaFX, LibGDX, etc.) that have only logic like the Sieve of Eratosthenes and Goldbach'e Conjecture. Can anyone give me concepts to learn that will be helpful in Programming competitions? I can send some of the questions of the programming competition in the previous years to get help in it. Thanks!
22 Replies
JavaBot
JavaBot5w ago
This post has been reserved for your question.
Hey @MDT 168! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Madjosz
Madjosz5w ago
How is Goldbach's conjecture relevant for programming?
MDT 168
MDT 168OP5w ago
"Every even number greater than 2 can be written as the sum of two prime numbers" I know this One of the questions in the competition, one of the medium difficulty ones is taking n as an input (Scanner), and printing out 4 prime numbers that sum up to that n And a lot of problems turned out to be famous concepts That is why I want to learn them
Madjosz
Madjosz5w ago
You could train algorithms by solving coding challenges on platforms like Codewars, Leetcode, Hackerrank, Project Euler, CodinGame etc. Also solving last years problems is always a good way to train.
MDT 168
MDT 168OP5w ago
Okay thank you so much for the websites! The problem that I don't understand last years questions. Dynamic Programming. (The difficult ones)
Madjosz
Madjosz5w ago
The thing is that it is hard to say "learn X and you will improve in algorithmic thinking". It's something which will come just by itself with practicing. Of course you can memorize algorithms, and especially for graph-theoretical things it is at least good to know about what algorithms already have been discovered but in general, and especially for such number theoretical things like Goldbach conjecture there's nothing "general" to learn (apart maybe from some mathematical background in divisibility and advancing to group theory, but this is already super specific and depends on the actual problem you need to solve) Well you could post a task, and we could look if we figure something out.
MDT 168
MDT 168OP5w ago
Okay wait. It's not in english so let me translate it 🟡 Medium Question (Problem D – “Best Throw”) Story: Ali is playing a marble game with his friends. Each point on the 2D field has one coin. Ali can throw the marble in a straight line in one of four directions: Horizontally (0° or 180°) Vertically (90°) Diagonally (45° or -45°) Whenever the ball passes through a point, it collects the coin there. Your task: Given the coordinates of all coin positions, find the maximum number of coins Ali can collect with one throw in any of those directions. --- Input: First line: integer n — number of coordinates. (1 ≤ n ≤ 1000) Next n lines: each line has two integers x and y (−10⁴ ≤ x, y ≤ 10⁴) --- Output: Print one integer — the maximum number of coins that can be collected in one straight throw. --- Examples: Input: 4 1 8 4 5 3 6 1 4 Output: 3 Input: 3 2 3 4 4 8 6 Output: 1 --- Explanation: In the first case, three points line up diagonally, so Ali can collect 3 coins in one throw. In the second case, no three points align, so the maximum is 1. This is one of the problems in the 2025 competition (April). So the most recent competition The hard ones concepts are scary. So let's start with medium easy ones Even with a year of experience, it's scary.
Madjosz
Madjosz5w ago
Sorry, I was busy the last hour. So for that task it would be feasable to do a brute-force approach since you only have at most 1000 coins in a 2000×2000 grid so that means you need to check 12000 lines at most per case. The other option is to find a representative for each line (e.g. the x- or y-axis intersection point) and register each input point for each of the four lines it lies on and then take the max of all these values. This even needs only O(n) runtime and O(n) memory (where n is the number of input points).
JavaBot
JavaBot5w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
MDT 168
MDT 168OP4w ago
Not a problem. But I got a question. In the future programmers competition and in LeetCode. I see that it got constraints, are these constraints just to tell me what will be the input range and that it will be always valid, or I need to use if statements and if it's not in the range, end the program? If the constraints are just to tell me it will always be valid. I don't need to use try-catch and if statements right? I can directly use int num = scanner.nextInt(); as scanner is an Object of Scanner class. Without try-catch for invalid integers like string or decimals?
Madjosz
Madjosz4w ago
Yes, these constraints are (or at least should be) always valid. You don't need to check them. They are here for you to approximate if your solution will even be performant enough.
MDT 168
MDT 168OP4w ago
Thank you. I wasted a lot of time handling every error and constraint while training, so this should be a good info to know
Madjosz
Madjosz4w ago
So e.g. for the above task I first suggested brute-force because 12000 is still manageable. If the grid coordinates would be in the range of millions, this would not be feasable.
MDT 168
MDT 168OP4w ago
Yeah. I just solved something in LeetCode without looking at the constraints using brute force. But saw that the constraint may give me a high number which is not optimised, so I solved it in another way So Constraints are just to make your program as optimised as possible I think.
Madjosz
Madjosz4w ago
I'd say as optimized as needed. You don't need some fancy optimized graph algorithm when you can just check all possible 20 combinations.
MDT 168
MDT 168OP4w ago
Usually competitions use famous algorithms right? I gave one of the hard ones to AI, and it got the name of the task exactly, which I think means that I just need to train on algorithms, not code itself
Madjosz
Madjosz4w ago
Yes. You should first start to solve the task with easy examples on pen and paper. Then try to spot pattern and identify your steps. Only then you should start coding.
MDT 168
MDT 168OP4w ago
Okay thanks. Because I think my coding itself is not bad. Like I can see code for an algorithm and understand how it works. But the faster you submit your question, I think the better chance to win. So a pen and paper will be slow, No? I have to win, it will give a full scholarship to the whole team ;—; So I will try training on LeetCode, and solve past years tasks Will that be enough?
Madjosz
Madjosz4w ago
Over time you'll get better and can do the first two steps in your head most of the time.
MDT 168
MDT 168OP4w ago
Thanks for the help, I really needed it. Have a great day!
JavaBot
JavaBot4w ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot4w ago
Post Closed
This post has been closed by <@1021759889623756852>.

Did you find this page helpful?