Write a simple javascript program/algorithm

  • Tình trạng: Closed
  • Giải thưởng: $20
  • Các bài thi đã nhận: 16

Tóm tắt cuộc thi

Given:
- an array of N non-negative unique integers
- a sum non-negative integer S

Write javascript (ES6, e.g., Node.js) function that checks if any subset of the N integers can sum to S (the subsets could be from length 1 to N, we don't care about the length, just the sum), output an array:
- empty if no subset of the N integers can sum to S
- otherwise, each element of the array is another array with a subset that sums to S, thus the elements would be all the different ways we can form subsets of N that sum to S ; do not duplicate the elements of the array, and also do not miss any subset that sums to S. How about subsets [ a b ] and [ b a ] ? To avoid confusion, each element should be in numerical order, so only one of [ a b ] and [ b a ] would be included

console.log the array

e.g., N is 5, the array is [ 3 5 8 2 6 ] , S = 11
Answer: [ [ 2 3 6 ] , [ 3 8 ] , [ 5 6 ] ]

I will test on some sample inputs. For selecting a contest winner:
a) Correctness (not crashing or other bugs, and giving desired, correct answers) is 1st priority. Winner would be selected from the correct answers for my sample inputs
b) If more than one are correct, tie breakers:
- elegance
- don't use libraries if possible
- performance - very slow running code is less preferred
- timeliness - who submits earlier - only if all else is equal

Các kĩ năng yêu cầu

Bảng thông báo công khai

  • Brids
    Brids
    • cách đây 1 năm

    Dear Contest holder, why you did not announce the winner?

    • cách đây 1 năm
  • ItsTahmina21
    ItsTahmina21
    • cách đây 1 năm

    Should i consider the input array as sorted? Or the numbers are in random order?

    • cách đây 1 năm
  • tljafar
    tljafar
    • cách đây 1 năm

    Hi,

    • cách đây 1 năm

Làm thế nào để bắt đầu với cuộc thi

  • Đăng cuộc thi của bạn

    Đăng cuộc thi của bạn Nhanh chóng và dễ dàng

  • Nhận được vô số bài dự thi

    Nhận được vô số Bài dự thi Từ khắp nơi trên thế giới

  • Trao giải cho bài thi xuất sắc nhất

    Trao giải cho bài thi xuất sắc nhất Download File - Đơn giản!

Đăng cuộc thi ngay hoặc tham gia với chúng tôi ngay hôm nay!