NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

// QUESTION Production binaries are release of an application by company X from time to time.

// Now the binaries follow transitive properties, which means if v1 is compatible with v2 and v2 is compatible with v3. v1 and v3 are also compatible.

// You are given signature of two APIs, which are required to be developed.

// void addVersion(version,isCompatible) - API takes input of binary version in version, and if this binary is compatible with immediate previous version.
// e.g., addVersion(2,true) -> version v2 is compatible with v1
// addVersion(3,false) -> version v3 is not compatible with v2

// - This API is used by company X
// bool isCompatible(srcVer,targetVer) - API provides checking of a source version ( INT srcVer) is compatible with a target version (INT target version).

// e.g., isCompatible(2,1) -> true : version 1 & 2 are compatible
// isCompatible(2,3) -> false: version 2 & 3 are not compatible
// Complete the API for the same.


const STARTING_BUCKET = 1

let latestVersion = 0;
let latestBucket = 0;
const versions = {
// // version: bucket,
// 1: 1,
// 2: 1,
// 3: 1,
// 4: 3
}

const bucketVersions = {
// bucket: bucketCompatibility
// 1: 1,
// 2: 6,
// 3: 3,
// 4: 4,
// 5: 6
}


function addVersion(newVersion, isCompatible) {
if (Object.keys(versions).length === 0) {
versions[newVersion] = STARTING_BUCKET;
bucketVersions[STARTING_BUCKET] = STARTING_BUCKET;
latestVersion = newVersion;
latestBucket = STARTING_BUCKET;
return
}

if (isCompatible) {
versions[newVersion] = versions[latestVersion];
}
else {
const newBucket = versions[latestVersion] + 1
versions[newVersion] = newBucket;
bucketVersions[newBucket] = bucketVersions[latestBucket] + 1;
latestBucket = newBucket;
}

latestVersion = newVersion;
}

function isCompatible(srcVersion, targetVersion) {
return versions[srcVersion] === versions[targetVersion] ||
bucketVersions[versions[srcVersion]] === bucketVersions[versions[targetVersion]]
}

function makeCompatible(srcVersion, targetVersion) {
const latestBucketCompatibility = bucketVersions[latestBucket];
const newBucketCompatibility = latestBucketCompatibility + 1;

bucketVersions[versions[srcVersion]] = newBucketCompatibility;
bucketVersions[versions[targetVersion]] = newBucketCompatibility;

latestBucket = versions[srcVersion];
}


// QUESTION: Extended question:

// There are few legacy binaries which are added to compatibility, so you need to make another API

// void makeCompatible(srcVer,tarVer)

// in which one makes a certain source version (srcVer) compatible with target version ( tarVer )


function main() {
addVersion(1,true)
addVersion(2,true)
addVersion(3,false)
addVersion(4,true)
addVersion(5,true)
addVersion(6,true)
addVersion(7,false)

// console.log(isCompatible(2,1))
// console.log(isCompatible(2,3))

console.log(isCompatible(4,5)) // T
console.log(isCompatible(6,5)) // T
console.log(isCompatible(4,6)) // T
console.log(isCompatible(3,7)) // F

makeCompatible(7, 5)
console.log(isCompatible(7, 5)) // T
console.log(isCompatible(7, 4)) // T
}

main()
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.