BackmediumLinked Lists linked-lists medium

Insert Ingredients in Sorted Order Solution

Problem Statement

Given a sorted linked list and an array of new ingredients with their respective magical properties, insert the ingredients into the linked list in a way that maintains the sorted order.

Example 1
Input
4 1 2 3 4 newIngredients = [5,6,7]
Output
[1, 2, 3, 4, 5, 6, 7]

Explanation: The new ingredients are inserted at the end of the list while maintaining the sorted order.

Constraints

  • The input linked list must be sorted in ascending order.
  • The new ingredients must be provided in an array.
  • The linked list may contain duplicate elements.
  • The new ingredients may contain duplicate values.
  • The input linked list and new ingredients may be empty.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free