The Codeground

/* LeetCode: Relative Sort Array (Solution Beats 93%) Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1. Sort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2. Elements that do not appear in arr2 should be placed at the end of arr1 in ascending order. */ var relativeSortArray = function(arr1, arr2) { let ind = {}; for(let i=0;i<arr1.length;i++) { ind[arr1[i]] = (ind[arr1[i]] || 0) + 1; } let res= []; for(let i=0;i<arr2.length;i++) { while(ind[arr2[i]] > 0) { res.push(+arr2[i]) ind[arr2[i]]=ind[arr2[i]]-1; } } let newRes = []; for(let j of Object.keys(ind)) { while(ind[j] > 0) { newRes.push(+j) ind[j]=ind[j]-1; } } newRes.sort((a,b)=>a-b); return [...res, ...newRes]; }; let arr1 = [2,3,1,3,2,4,6,7,9,2,19] let arr2 = [2,1,4,3,9,6] console.log(relativeSortArray(arr1, arr2))
Hint: Remember to include output statements in your code, such as print, console.log, printf, fmt.Println() or System.out.println.

Benefits of TheCodeground Online IDE

Multi-Language Support

TheCodeground Online IDE supports C++, Java, Node.js, Python, and more, making it an incredibly versatile tool for diverse coding needs. This extensive language support allows developers to work on different projects within a single platform.

Real-Time Collaboration

Our real-time collaboration feature enables multiple developers to work on the same project simultaneously, enhancing teamwork and productivity. This feature is particularly beneficial for remote teams and pair programming sessions.

User-Friendly Interface

Designed with a clean and intuitive interface, TheCodeground Online IDE simplifies coding and debugging processes, making it accessible for users of all skill levels. The ease of use and clear navigation ensure a smooth coding experience.

Instant Code Execution

Experience fast and efficient code execution with immediate feedback in the integrated terminal. This feature helps streamline the development process, allowing developers to quickly test and debug their code.

Free to Use

Enjoy the full range of features at no cost. TheCodeground Online IDE is completely free, providing a valuable resource for developers without any subscription fees. This makes it an ideal choice for students, hobbyists, and professionals alike.

Cloud-Based Platform

As a cloud-based IDE, TheCodeground allows you to access your projects from anywhere, at any time. This flexibility ensures that you can continue coding without being tied to a specific device or location.

Customizable Environment

Tailor the IDE to your preferences with customizable themes, layouts, and extensions. This personalization ensures a comfortable and productive coding environment.

Why Choose TheCodeground Over Other Online IDEs?

TheCodeground Online IDE stands out from the competition with its comprehensive feature set, ease of use, and cost-effectiveness. Unlike many other online IDEs that require subscriptions or offer limited free plans, TheCodeground provides all its features for free. Our multi-language support, real-time collaboration, and advanced debugging tools ensure that you have everything you need for effective development. Additionally, our user-friendly interface and customizable environment make coding a pleasant experience, regardless of your expertise level. Choose TheCodeground Online IDE for a seamless, efficient, and enjoyable coding experience.

×
Ground visible to everyone?
No
Yes
Ground editable by everyone?
No
Yes
Get a new ground?