coin row problem in linear time
/*
Assumptions :
1. The numbers are integers and given as strings.
2. The array of numbers is basically a 2D string array where each
elemet (number) is represented as a string
*/
char* coin_row_problem(char **arr, int n)
{
char* prev;
if(n==0)
{
prev = (char*)calloc(2, sizeof(char));
prev[0] = '0';
prev[1] = '\0';
}
prev = (char*)calloc(2, sizeof(char));
prev[0] = '0';
prev[1] = '\0';
char *zero = (char*)calloc(2, sizeof(char));
zero[0] = '0';
zero[1] = '\0';
char *curr = intal_add(arr[0], prev);
char *nxt;
char *sub;
char *toFree;
for(int i = 1 ; i < n ; ++i)
{
sub = intal_add(prev, arr[i]);
if(intal_compare(sub, curr)==1)
{
nxt = sub;
}
else
{
nxt = intal_add(curr, zero);
free(sub);
}
toFree = prev;
prev = curr;
curr = nxt;
free(toFree);
}
free(prev);
free(zero);
return curr;
}
Also in C:
- the best programming language in 2021
- fwrite c
- undefined reference to `cv::VideoCapture::VideoCapture(cv::String const&)'
- create point cloud from rgbd image in open3d v0.10
- modulation
- arduino client disconnect
- matrix pointer c
- where is my vimrc
- how to login to another user in powershell
- resto de division recursiva
- c program to find number of days in a month using switch case
- convert string to uppercase in c
- pi in c language
- fgets c
- intellij idea
- c check if char is number
- sdl texture error
- code: 'EADDRINUSE', [0] errno: 'EADDRINUSE', [0] syscall: 'listen', [0] address: '::', [0] port: 5000
- reverse function in c
- check if string starts with c
- arduino keypad wait for key
- how to create random integers from a specific range in c language
- lazer codechef
- plt hide axis ticks