Kristinbarr / code-challenges

A place to keep various coding challenges completed with solutions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CODE CHALLENGE PRACTICE

A place to keep various coding challenges I have completed with solutions.

TABLE OF CONTENTS

JavaScript Python
Palindrom Number
Zigzag Conversion
Next Permutation
Reverse Integer Reverse Integer
Two Sum
Add Two Numbers
Adjacent Elements Product

PROBLEMS LIST

Palindrome Number

Task:

Example:

πŸ”— Link to Challenge (Leetcode)

Zigzag Conversion

Task: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

P   A   H   N
A P L S I I G
Y   I   R

And then read line by line: "PAHNAPLSIIGYIR"

Write the code that will take a string and make this conversion given a number of rows:

string convert(string s, int numRows);

Example:

Input Output
s = "PAYPALISHIRING", numRows = 3 "PAHNAPLSIIGYIR"
s = "PAYPALISHIRING", numRows = 4 "PINALSIGYAHRPI"
P     I    N
A   L S  I G
Y A   H R
P     I

πŸ”— Link to Challenge (Leetcode)

πŸ‘€ See My JavaScript Solution


Next Permutation

Task:

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must be rearranged as the lowest possible order (ie, sorted in ascending order). The replacement must be in-place and use only constant extra memory.

Example:

Input Output
1,2,3 1,3,2
3,2,1 1,2,3
1,1,5 1,5,1

πŸ”— Link to Challenge (Leetcode)

πŸ‘€ See My JavaScript Solution


Reverse Integer

Task: Given a 32-bit signed integer, reverse digits of an integer.

Note: Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [βˆ’231, 231 βˆ’ 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.

Example:

Input Output
123 321
-123 -321
120 21

Note:

Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [βˆ’231, 231 βˆ’ 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.

πŸ”— Link to Challenge (Leetcode)

πŸ‘€ See My JavaScript Solution

πŸ‘€ See My Python Solution


Two Sum

Task:

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example:

Input Output
nums = [2, 7, 11, 15], target = 9 [0, 1]

Note:

Make sure you are returning the indicies of the values, not the values themselves.

πŸ”— Link to Challenge (LeetCode)

πŸ‘€ See My JavaScript Solution


Add Two Numbers

Task:

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

Example:

Input Output Explaination
nums = (2 -> 4 -> 3) + (5 -> 6 -> 4) 7 -> 0 -> 8 342 + 465 = 807

πŸ”— Link to Challenge (LeetCode)

πŸ‘€ See My JavaScript Solution


Adjacent Elements Product

Task:

Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.

Example:

Input Output
[3, 6, -2, -5, 7, 3] 21

Guaranteed constraints: 2 ≀ inputArray.length ≀ 10, -1000 ≀ inputArray[i] ≀ 1000.

πŸ”— Link to Challenge (CodeSignal)

πŸ‘€ See my JavaScript Solution


About

A place to keep various coding challenges completed with solutions


Languages

Language:JavaScript 63.7%Language:Python 36.3%