Coder Social home page Coder Social logo

anosharehan / coding-challenges Goto Github PK

View Code? Open in Web Editor NEW
78.0 2.0 44.0 16 KB

This repository contains solutions to coding challenges from websites like Hackerrank, Coderbyte, etc.

Home Page: https://www.hackerrank.com/, https://coderbyte.com/

Python 100.00%
python3 coderbyte-solutions python coderbyte seating-students hackerrank-solutions dam-design hackerrank min-difference html-dom-element

coding-challenges's Introduction

This repository contains coding solutions from online coding challenges. The coding problems solved so far are as follows:

  • Seating-Students-Coderbyte: This is a medium level question from Coderbyte.
  • Dam-Design-Hackerrank: This is a medium level question from Hackerrank.
  • Minimum-Difference-Hackerrank: A function accepts an array and returns the sum of absolute minimum difference of the array.
  • HTML-Elements-Coderbyte: This is a medium level question from Coderbyte and is about balancing HTML DOM Elements provided as a string.
  • Letter-Count-Coderbyte: The function LetterCountI takes the str parameter being passed and return the first word with the greatest number of repeated letters.
  • Command-Line-Coderbyte: The function CommandLine takes the str parameter being passed which represents the parameters given to a command in an old PDP system.
  • Stock-Picker-Coderbyte: The function StockPicer takes the arr parameter which will contain integers that represent the amount in dollars that a single stock is worth, and return the maximum profit that could have been made by buying stock.
  • Array-Addition-Coderbyte: The function ArrayAdditionI accepts an interger array and returns true if a summation of any elements in the array equal to the largest value in the array or false when no combination of elements equals the largest element.
  • Mutating-Array-CodeSignal
  • Dom-Tree-Codility: You are given a DOM tree and have to find the table with the largest number of cells within it.

Questions are provided in the respective program files. Contribution/Optimized solutions will be appreciated

coding-challenges's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

coding-challenges's Issues

Array addition will always return False

''''

Have the function ArrayAdditionI(arr) take the array of numbers stored in arr
and return the string true if any combination of numbers in the array can be
added up to equal the largest number in the array, otherwise return the string
false. For example: if arr contains [4, 6, 23, 10, 1, 3] the output should
return true because 4 + 6 + 10 + 3 = 23. The array will not be empty, will not
contain all the same elements, and may contain negative numbers.

Examples:

Input: [5, 7, 16, 1, 2]
Output: false

Input: [3, 5, -1, 8, 12]
Output: true

'''

def ArrayAdditionI(arr):
arr = sorted(arr)
maximum = arr[-1]
arr = arr[:1]
total = 0

for i in range(len(arr)):

	total = total + arr[i]
	if total == maximum:
		return 'true'
	
	for j in range(len(arr)):
		if j != i:
			total = total + arr[j]
			if total == maximum:
				return 'true'
	
	for k in range(len(arr)):
		if k != i:
			total = total + arr[k]
			if total == maximum:
				return 'true'
	
	return 'false'

print(ArrayAdditionI([3, 5, -1, 8, 12]))

some flaw in Array addition

arr = arr[:1]

why not we can do like below?

def ArrayAdditionI_Fast(arr):
arr = sorted(arr)
print(arr)
max_value = arr[-1]
arr = arr[:-1]
print(arr)
arr = arr[:1]
print(arr)
total = 0
for i in arr:
total = total + i
return 'True' if total == max_value else 'False'

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.