GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — leetcode/problems/largest-divisible-subset at master · ecgan/leetcode

Expand file tree

/

largest-divisible-subset

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

largest-divisible-subset

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
README.md
README.md
 
 
largestDivisibleSubset.js
largestDivisibleSubset.js
 
 
largestDivisibleSubset.test.js
largestDivisibleSubset.test.js
 
 

README.md

Outline

Largest Divisible Subset

LeetCode #: 368

Difficulty: Medium

Topics: Math, Dynamic Programming.

Problem

Given a set of distinct positive integers, find the largest subset such that every pair (S[i], S[j]) of elements in this subset satisfies:

S[i] % S[j] = 0 or S[j] % S[i] = 0.

If there are multiple solutions, return any subset is fine.

Example 1:

Input: [1,2,3]
Output: [1,2] (of course, [1,3] will also be ok)

Example 2:

Input: [1,2,4,8]
Output: [1,2,4,8]

Solution Explanation

Reference: 4 lines in Python by StefanPochmann

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.