Questions tagged [programming-challenge]

Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.

Filter by
Sorted by
Tagged with
2
votes
1answer
54 views

LeetCode 552: Student Attendance Record II

I'm posting my code for a LeetCode problem copied here. If you have time and would like to review, please do so. Thank you! Problem Given a positive integer n, return the number of all possible ...
0
votes
1answer
70 views

LeetCode 1320: Minimum Distance to Type a Word Using Two Fingers II

I'm posting my Python code for LeetCode's 1320. If you have time and would like to review, please do so. Problem You have a keyboard layout as shown above in the XY plane, where each English ...
1
vote
1answer
53 views

LeetCode 1320: Minimum Distance to Type a Word Using Two Fingers I

I'm posting my C++ code for LeetCode's 1320. If you have time and would like to review, please do so. Thank you! Problem You have a keyboard layout as shown above in the XY plane, where each English ...
-1
votes
1answer
55 views

LeetCode 375: Guess Number Higher or Lower II

I'm posting my C++ code for LeetCode's Guess Number Higher or Lower II. If you have time and would like to review, please do so. Problem We are playing the Guess Game. The game is as follows: I pick ...
2
votes
0answers
57 views

LeetCode 200: Number of Islands

I'm posting my code for a LeetCode problem. If you'd like to review, please do so. Thank you for your time! Problem Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. ...
7
votes
1answer
68 views

“Jedi's riddle” challenge

The challenge can be found here. In short we have a recursive function, and we need to find when \$z_i\$ is equal to one. $$ \begin{align} z_1 &= 1\\ z_i &= z_{i-1} * a\ \%\ n\\ \...
2
votes
1answer
68 views

LeetCode 146: LRU Cache III

I'm posting my Java code for LeetCode's LRU Cache. If you have time and would like to review, please do so. Thank you! Problem Design and implement a data structure for Least Recently Used (LRU) ...
2
votes
1answer
74 views

LeetCode 146: LRU Cache II

I'm posting my code for a LeetCode problem. If you'd like to review, please do so. Problem Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following ...
5
votes
1answer
99 views

LeetCode 146: LRU Cache I

I'm posting my C++ code for LeetCode's LRU Cache. If you have time and would like to review, please do so. Thank you! Problem Design and implement a data structure for Least Recently Used (LRU) cache....
2
votes
0answers
27 views

Lispy code? Palindrome of product

My answer to Project Euler problem 4 (largest palindrome of product of two 3-digit numbers) is below. Please suggest improvements, style changes, indentation, commenting, naming, ... And nitpicks are ...
2
votes
2answers
126 views

LeetCode 1044: Longest Duplicate Substring

I'm posting my C++ code for LeetCode's Longest Duplicate Substring. If you have time and would like to review, please do so. Thank you! Problem Given a string S, consider all duplicated substrings: (...
1
vote
1answer
59 views

LeetCode 1146: Snapshot Array

I'm posting my C++ code for LeetCode's Snapshot Array. If you have time and would like to review, please do so. Thank you! Problem Implement a SnapshotArray that supports the following interface: ...
1
vote
1answer
64 views

LeetCode 399: Evaluate Division

I'm posting my C++ code for LeetCode's Evaluate Division. If you have time and would like to review, please do so. Thank you! Problem Equations are given in the format A / B = k, where A and B are ...
1
vote
1answer
60 views

LeetCode 809: Expressive Words

I'm posting my C++ code for LeetCode's Expressive Words. If you have time and would like to review, please do so. Thank you! Sometimes people repeat letters to represent extra feeling, such as "...
8
votes
2answers
414 views

Alphabet Rangoli Challenge

The question is about printing alphabets in a rangoli pattern of size/dimension input by the user. Example: ...
1
vote
0answers
45 views

ReadAsync: Continuously reads stream and spits out Packets and Fill incomplete Packets

I have difficulties when sometimes a game client sends a list of packet in the same buffer, where it is split before processing. The biggest problem is when any packets don't come complete. For ...
4
votes
1answer
56 views

Finding all factors and prime factors of a number

I am working on the Project Euler, number 3 project (finding the largest prime factor of 600851475143), but I wanted to take it a step further and write something that will list all factors and prime ...
1
vote
0answers
66 views

LeetCode 218: The Skyline Problem II

Here I'm posting my Java code for the skyline problem. If you have time and would like to review, please do so, I'd appreciate that. Problem A city's skyline is the outer contour of the silhouette ...
1
vote
1answer
52 views

Exercism: Class representation of a matrix in Python

The task is to represent a Matrix as a class and to instantiate it from a string such as "1 2 3 4\n5 6 7 8\n9 8 7 6" The class must provide methods for ...
1
vote
0answers
108 views

LeetCode 767: Reorganize String

Here I'm posting my Java code for the Reorganize String problem on LeetCode. If you have time and would like to review, please do so, I'd appreciate that. On LeetCode, we are only allowed to change ...
-4
votes
1answer
47 views

Time limit exceeds in this simple program [closed]

Link to problem: https://www.codechef.com/JUNE20B/problems/EVENM Iam trying to solve a simple problem challenge, but getting TLE. I had a different approach earlier, so tried this, again with no ...
-1
votes
1answer
73 views

LeetCode 76: Minimum Window Substring - Python

I'm posting a two-pointer, sliding-window problem of LeetCode (Minimum Window Substring) solved with Python. If you have time and would like to review the code, please do so, I appreciate that. On ...
0
votes
1answer
76 views

LeetCode 76: Minimum Window Substring

I'm posting an sliding window problem of LeetCode (Minimum Window Substring) with C++. If you have time and would like to review the code, please do so, I appreciate that. On LeetCode, we are only ...
0
votes
1answer
94 views

LeetCode 76: Minimum Window Substring - Java

I'm posting my Java code for the Minimum Window Substring. If you have time and would like to review, please do so, I appreciate that. Problem Given a string string...
6
votes
3answers
275 views

C: function to read a token from stdin

I recently started doing some competitive programming in C and one of my first requirements was a high-speed token reader (analogous to the java Scanner class' <...
0
votes
5answers
721 views

LeetCode 1: Two Sum

This is an easy level LeetCode question, obviously not much code to review. I'm posting C++/Java/Python here. If you'd like to review, please do so. Thank you! Problem Given an array of integers, ...
6
votes
1answer
73 views

Vowels and Consonants

From HackerRank's 10 Days of JavaScript, Day2: Loops: Complete the vowelsAndConsonants function in the editor below. It has one parameter, a string,s, consisting of lowercase English alphabetic ...
1
vote
1answer
64 views

Speeding up pandas apply

I would like to speed up pandas apply function. I have been using swifter . It currently takes about 5 mins for 200000 records using multiprocessing as below . Is there any way to speed this up ...
3
votes
2answers
63 views

Using deque for composing a string from 2 alternating stacks

We have 2 strings, say "JACK" and "DANIELS". We create two stacks from these strings, and then loop over them comparing first elements: whichever of the 2 goes first in lexicographic order gets popped ...
2
votes
1answer
47 views

Aho-Corasick algorithm to scan through a list of strings

This is a follow-up to my previous question about finding min and max values of an iterable. Aho-Corasick algorithm was suggested to solve the problem. Below is my solution with the use of ahocorapy ...
3
votes
2answers
82 views

Checking if naughts or crosses win in Tic Tac Toe

I am working on a coding challenge for Tic Tac Toe. I am calculating the results and inserting them into the database. However I have a long and messy if statement, which checks if the array's values ...
1
vote
2answers
58 views

Recursive brute-force approach to maximum points you can obtain from cards

I came across this question on Leetcode. The question description is as follows: There are several cards arranged in a row, and each card has an associated number of points. The points are given in ...
2
votes
0answers
37 views

Finding number of brackets sequences of length n containing a specific string s

I am trying to solve a problem where I need to find the number of bracket sequences \$p\$ and \$q\$ such that for a given bracket sequence s. I have that \$p + s + q\$ is a valid bracket sequence. ...
2
votes
1answer
130 views

Count number of previous elements greater than its element at present index

Suppose I have a vector containing n elements. I want to find out the number of previous elements greater than its element at present index i. I want to find ...
2
votes
1answer
50 views

Count “Word Order” with further optimization

Question: You are given n words. Some words may repeat. For each word, print its number of occurrences. The output order should correspond with the input order of ...
7
votes
2answers
281 views

Finding min and max values of an iterable on the fly

This is a follow up for my question about optimizing solution for DNA Health HackerRank problem. Short re-cap: You are given 2 arrays (genes and ...
2
votes
1answer
151 views

How to apply Python generators to finding min and max values?

I'm solving yet another problem in HackerRank (https://www.hackerrank.com/challenges/determining-dna-health/problem). In short: you are given 2 arrays (genes and <...
3
votes
1answer
57 views

Optimizing code solution for Palindrome Index-Hackerrank

I submitted my solution for palindrome Index coding challenge but I get "test cases terminated due to time out error". My code is working and so I don't know what else to do to optimize it. Please ...
3
votes
1answer
70 views

Max sum of abs difference in array

I am just trying to understand the algorithm of the problem statement Given an array, we need to find the maximum sum of absolute difference of any permutation of the given array. Here is my ...
4
votes
2answers
110 views

Maxcounters in JavaScript

I am trying to solve this question: MaxCounters. Solving it is straightforward, but solving it fast enough is proving very difficult. How can I improve the performance of this code? At the moment it ...
3
votes
1answer
104 views

Ruby simple interactive interpreter

This is a solution to this problem: https://www.codewars.com/kata/53005a7b26d12be55c000243/train/ruby The task is to make a simple interpreter that will take expressions and calculate the results. I'...
5
votes
1answer
92 views

Sort Characters By Frequency Java

For context, I worked on the LeetCode May 2020 Challenge Week 3 Day 1. The challenge was described as this: Given a string, sort it in decreasing order based on the frequency of characters. ...
2
votes
1answer
61 views

Leetcode Search in Rotated Sorted Array

I was doing Search in sorted array question from leetcode Question Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,...
-2
votes
1answer
65 views

How to work in linear time with DFS

I tried a Hackerrank problem and it gives me a successful message, it works fine for Hackerrank criteria. The member states of the UN are planning to send 2 people to the moon. They want them to be ...
4
votes
1answer
118 views

Leetcode three sum in Javascript

I was doing 3sum question on leetcode Question Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum ...
2
votes
0answers
36 views

Project Euler #14: Longest Collatz sequence on HackerRank

The following is the conclusion in a long chain of attempts to solve Project Euler problem #14 (Longest Collatz sequence) on HackerRank in the Haskell programming language. The problem is defined as ...
1
vote
1answer
103 views

arithmetic with numbers and letters

I've started learning JavaScript last week. Today I ran into a JS exercise available at this link codewars exercise and decided to give it a try. I've used very basic JS because I know only a small ...
5
votes
4answers
215 views

LeetCode: Roman to Integer in Java

I tried solve this easy leetcode challenge in java. Challenge link Here is my solution ...
10
votes
3answers
2k views

Simple Sudoku Solver in Python

This is my naive approach on implementing a Sudoku solver, which is okay for simple Sudokus like this: ...
5
votes
3answers
76 views

Add two digit strings and return the result as string

I haven't done C in a while. This looks like a simple problem to start. Leetcode problem 415 Given two non-negative integers num1 and ...

1
2
3 4 5
60