All Questions
34 questions
8
votes
2
answers
196
views
Leetcode 93: Restore IP Addresses (C version)
This is posted in response to this request made in a discussion of my "C-ish" answer to a recent Code Review question regarding a Python solution to a Leetcode challenge. It was reported ...
4
votes
2
answers
308
views
Count frequency of words and print them in sorted order
Objective:
Write a program to count the frequencies of unique words from standard input, then print them out with their frequencies, ordered most frequent first. For example, given this input:
...
4
votes
3
answers
144
views
Simple photomosaic generator
I wrote an implementation of Robert Heaton's Programming Exercise for Advanced Beginners #4 (photomosaics) in C99 using the MagickCore library. The full code is as follows:
...
1
vote
2
answers
529
views
Checking the type and validity of a credit card with Luhn's algorithm in C (CS50)
I'm taking CS50 Intro to CS. In this assignment, we're asked to make a program that can identify what type of credit card (AMEX, Visa, MasterCard) is given in the input (and whether it is valid.) ...
5
votes
3
answers
1k
views
Printing pyramids in C (CS50)
I'm taking the CS50 course, and we're asked to create a program which takes an input (the total height of the pyramid) and outputs a pyramid of that height.
i.e Here’s how the program might work if ...
3
votes
1
answer
131
views
palindrome code in C times out in program challenge?
Hello I am making a code in C to find the value of the last sequence of palindromes of a specified size (d) and I need to optimize this code as it is for an ...
3
votes
2
answers
266
views
LeetCode 665: Non-decreasing Array (C)
I'm posting a solution for LeetCode's "Non-decreasing Array". If you'd like to review, please do. Thank you!
Problem
Given an array nums with ...
9
votes
3
answers
2k
views
LeetCode 1108: Defanging an IP Address
I'm posting two solutions for LeetCode's "Defanging an IP Address". If you'd like to review, please do. Thank you!
Problem
Given a valid (IPv4) IP address, return a defanged version of that ...
2
votes
0
answers
278
views
Performance challenge: Box operations (HackerRank) (C, Python)
Recently I've been doing some challenges on HackerRank and came across this one. First, I tried with Python, and then C. Both of my codes failed due to timeout restrictions.
It would be very helpful, ...
2
votes
1
answer
96
views
Permutation code in C
I am pretty new to competitive programming. It took me almost 3 hours to make this, initially I started with 4 for loops and then to make it scalable for sizes bigger than 4, I decided to turn this ...
4
votes
1
answer
258
views
C functions for fast IO for competitive programming
In some (perhaps not well-designed) competitive programming problems,
the runtime and score is dependent on how fast your program can
process input. Therefore I've written a small C99 library with ...
5
votes
0
answers
89
views
Finding duplicates in an array using C [closed]
I came across a problem on LeetCode.
There is an input array of integers. I need to find out if there any repeating integers, then return true else false.
So, I tried using a hashtable library ...
2
votes
2
answers
448
views
Calculating triangular numbers
A triangular number is a product of three factors as follows:
$$
\text{Triangular number} = x(x + 1)(x + 2)
$$
Is there a way to make this code faster? As it is the code calculates every triangular ...
5
votes
1
answer
5k
views
Code Vita: Chakravyuha
Problem Statement
A Chakravyuha is a wheel-like formation. Pictorially it is depicted as
below
A Chakravyuha has a very well-defined co-ordinate system. Each point
on the co-...
9
votes
2
answers
288
views
Tail implementation using a dynamic queue library
As per K & R exercise 5-13
Write the program tail, which prints the last n lines of its input. By default, n is 10, say, but it can be changed by an optional argument, so that
...