GithubHelp home page GithubHelp logo

ahmedfathydev / hackerrank-solutions Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 1.0 392 KB

HackerRank's challenges solutions. Above 350 solutions.

License: GNU General Public License v2.0

C++ 49.39% C 42.61% Shell 0.38% Java 1.83% JavaScript 4.38% CSS 0.32% HTML 1.08%
algorithms bash c competitive-programming cpp data-structures hackerrank hackerrank-solutions java javascript linux-shell online-judge problem-solving python3 shell sql

hackerrank-solutions's Introduction

Summary

  • One year of experience in web application development using .NET Core Framework.

  • Proficient in Object-Oriented Programming, Data Structures, Algorithms, Design Patterns, and Problem Solving.

  • Eager learner passionate about advancing skills in .NET, Back-End technologies, DevOps, and emerging trends like Web 3, Blockchain, Linux, and Cloud Computing.

  • Detail-oriented and committed engineer known for on-time delivery of high-quality products. Self-motivated and quick learner.

  • ๐Ÿ‘จโ€๐Ÿซ Currently studying at: Open Source Society University - Computer Science

  • ๐Ÿ”ญ Looking to collaborate on: JobWebsites and FreelanceWebsites.

Skills

{
    "skills": [
        "C#",                                   "ASP.NET Core Web API",     "Entity Framework Core",
        "Database Systems",                     "JSON Web Token (JWT)",     "Language Integrated Query (LINQ)",
        ".NET Core",                            "ASP.NET Core MVC",         "Microsoft Azure",
        "Software Engineering Practices",       "Clean Code",               "Unit Testing",
        "Microservices",                        "Cloud Computing",          "Problem Solving",
        "Object-Oriented Programming (OOP)",    "Data Structures",          "Algorithms",
        "SQL",                                  "Git",                      "Unix / Linux"
    ]
}

Contribution Activity





Loading...

hackerrank-solutions's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mahmoudhamdy00

hackerrank-solutions's Issues

Strings (Algorithms)

Post Transition

Not completed solution for Post Transition problem

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct package {
	char *ID;
	int weight;
    struct package *nextPtr;
};

typedef struct package Package;
typedef Package* PackagePtr;

struct postOffice {
	int minWeight;
	int maxWeight;
	int packagesCount;
    Package *packagesHeadPtr;
    Package *packagesTailPtr;
};

typedef struct postOffice PostOffice;

struct town {
	char name[6];
	int officesCount;
	PostOffice *offices;
};

typedef struct town Town;

void dequeue(PackagePtr *headPtr, PackagePtr *tailPtr) {
	PackagePtr tempPtr = *headPtr;
	*headPtr = (*headPtr)->nextPtr;

	if(*headPtr == NULL) {
		*tailPtr = NULL;
	}

    free(tempPtr->ID);
    tempPtr->ID = NULL;
	free(tempPtr);
	tempPtr = NULL;
}

void enqueue(PackagePtr *headPtr, PackagePtr *tailPtr, char ID[], int weight) {
	PackagePtr newPtr = malloc(sizeof(Package));
	
	if (newPtr == NULL) {
        exit(EXIT_FAILURE);
	}

	newPtr->ID = malloc(6 * sizeof(char));
    newPtr->ID = ID;
    newPtr->weight = weight;
	newPtr->nextPtr = NULL;

	if (*headPtr == NULL) {
		*headPtr = newPtr;
	} else {
		(*tailPtr)->nextPtr = newPtr;
	}

	*tailPtr = newPtr;
}


int findTown(Town towns[], int townsCount, char townName[]) {
    for (int i = 0; i < townsCount; i++) {
        if (!strcmp(townName, towns[i].name)) {
            return i;
        }
    }
    return -1;
}

void sendAllAcceptablePackages(Town towns[], int sourceOfficeIndex, int targetOfficeIndex) {
    PackagePtr currentPackage = towns[sourceOfficeIndex].offices->packagesHeadPtr;

    while (currentPackage != NULL) {
        if (currentPackage->weight >= towns[targetOfficeIndex].offices->minWeight &&
            currentPackage->weight <= towns[targetOfficeIndex].offices->maxWeight
        ) {
            enqueue(&towns[targetOfficeIndex].offices->packagesHeadPtr, 
                &towns[targetOfficeIndex].offices->packagesTailPtr, 
                towns[sourceOfficeIndex].offices->packagesHeadPtr->ID, 
                towns[sourceOfficeIndex].offices->packagesHeadPtr->weight
            );
        } else {
            enqueue(&towns[sourceOfficeIndex].offices->packagesHeadPtr, 
                &towns[sourceOfficeIndex].offices->packagesTailPtr, 
                towns[sourceOfficeIndex].offices->packagesHeadPtr->ID, 
                towns[sourceOfficeIndex].offices->packagesHeadPtr->weight
            );
        }
        dequeue(&towns[sourceOfficeIndex].offices->packagesHeadPtr, 
            &towns[sourceOfficeIndex].offices->packagesTailPtr
        );
    }
}

int main(int argc, char *argv[]) {

    int townsCount, queries;
	scanf("%i", &townsCount);
	Town* towns = malloc(townsCount * sizeof(Town));

	for (int i = 0; i < townsCount; i++) {

		scanf("%s%i", towns[i].name, &towns[i].officesCount);
		towns[i].offices = malloc(towns[i].officesCount * sizeof(PostOffice));

		for (int j = 0; j < towns[i].officesCount; j++) {
			scanf("%i%i%i",
                &towns[i].offices[j].packagesCount,
                &towns[i].offices[j].minWeight,
                &towns[i].offices[j].maxWeight
            );
			towns[i].offices[j].packagesHeadPtr = NULL;
            towns[i].offices[j].packagesTailPtr = NULL;

			for (int k = 0; k < towns[i].offices[j].packagesCount; k++) {
                char ID[6];
                int weight;
				scanf("%s%i", ID, &weight);
                enqueue(&towns[i].offices[j].packagesHeadPtr,
                    &towns[i].offices[j].packagesTailPtr,
                    ID,
                    weight
                );
			}
		}
	}

	scanf("%i", &queries);

	while (queries--) {

        char townName[6];
		int type, sourceOfficeIndex, targetOfficeIndex, townIndex;

		scanf("%i", &type);

		switch (type) {
		case 1:
			scanf("%s", townName);
			int townIndex = findTown(towns, townsCount, townName);
			printf("%s:\n", towns[townIndex].name);
            for (int i = 0; i < towns[townIndex].officesCount; i++) {
                printf("\t%i:\n", i);
                PackagePtr currentPackage = towns[townIndex].offices[i].packagesHeadPtr;
                while (currentPackage != NULL) {
                    printf("\t\t%s\n", currentPackage->ID);
                    currentPackage = currentPackage->nextPtr;
                }
            }
			break;
		case 2:
			scanf("%s%i%s%i", townName, &sourceOfficeIndex, townName, &targetOfficeIndex);
			sendAllAcceptablePackages(towns, sourceOfficeIndex, targetOfficeIndex);
			break;
		case 3:
            for (int i = 0, packages = 0, maxPackages = -1; i < townsCount; i++, packages = 0) {
                for (int j = 0; j < towns[i].officesCount; j++) {
                    packages += towns[i].offices[j].packagesCount;
                }
                if (packages > maxPackages) {
                	maxPackages = packages;
                    townIndex = i;
                }
            }
			printf("Town with the most number of packages is %s\n", towns[townIndex].name);
			break;
		}
	}

	return EXIT_SUCCESS;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.