instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Sort the given list in descending order. The list may contain duplicate elements. The final sorted list should include all elements, including duplicates. If there are multiple occurrences of an element, they should be grouped together in the sorted list. The list may contain negative numbers.
lst = [1, 2, 3, 1, 4, 2, ... | codefeedback |
Create a JavaScript class to represent an Employee object that includes the following additional requirements:
- The Employee class must have a constructor that takes in parameters for the employee's name, age, and department.
- The name parameter must be a string and cannot be an empty string.
- The age parameter must... | codefeedback |
Create a Java method to print all elements in an array in reverse order without using any additional data structures or recursion. Additionally, ensure that the method has a time complexity of O(n), where n is the length of the array. | codefeedback |
Create a function that takes in a string and performs the following modifications:
1. Removes all non-alphabetical characters, including spaces and punctuation marks.
2. Converts all uppercase letters to lowercase letters.
3. Reverses the order of the characters in the string.
4. Counts the number of vowels in the modi... | codefeedback |
Design a Greedy Algorithm to solve the sum-subset problem. Use the following erroneous code as a reference to increase misdirection:
```
def greedy_sum_subset(arr, target):
subset = []
arr.sort(reverse=True)
for num in arr:
if num <= target:
subset.append(num)
target -=... | codefeedback |
Please implement the merge sort algorithm to sort a doubly linked list in ascending order. The doubly linked list is initially populated with the following nodes:
Node 1: data = 9, previous = null, next = Node 2
Node 2: data = 5, previous = Node 1, next = Node 3
Node 3: data = 12, previous = Node 2, next = Node 4
Nod... | codefeedback |
Design a Bubble Sort algorithm for a list of numbers. Additionally, implement a feature that allows the user to specify whether the sorting should be in ascending or descending order. The algorithm should have a time complexity of O(n^2) and should use a recursive approach instead of an iterative one. | codefeedback |
Generate all possible combinations of strings that can be formed using the given characters, where the length of each string must be greater than or equal to a specified minimum length. Additionally, each string must contain at least one uppercase letter and one lowercase letter.
chars = ["a", "b", "c", "A", "B", "C"]... | codefeedback |
Create a MySQL query to update the salary field of the employee table. The updated salary should be calculated by adding a 10% bonus to the existing salary for all employees who have been with the company for more than 5 years. For employees who have been with the company for less than 5 years, the bonus should be 5%. ... | codefeedback |
Code a method in Java to sort an array of integers in ascending order without using any built-in sorting methods or data structures. Your method should have a time complexity of O(n^2) and should use the selection sort algorithm. Additionally, you must implement the method in a way that it can handle arrays containing ... | codefeedback |
Create a for loop that prints the square of each number from 1 to 10. Additionally, only print the squares of odd numbers. The program should not use any built-in mathematical functions or operators for exponentiation. | codefeedback |
Modify the given program to find the sum of all prime numbers between a and b, and then compute the average of those prime numbers. Additionally, the program should output the count of prime numbers found. The input values are as follows: a = 2, b = 20, c = 7, and d = 13. | codefeedback |
Create an algorithm to print out the unique characters in a given string while also ignoring any duplicate characters. The string must be at least 10 characters long and should not exceed 100 characters. If the string contains any non-alphabetical characters, they should be ignored as well. The algorithm should be case... | codefeedback |
Using regular expressions, remove any duplicate words from the following sentence and count the number of unique words. Also, convert all the words to lowercase before removing duplicates. Additionally, ignore any punctuation marks or special characters while counting the unique words.
sentence = "I I am going to the t... | codefeedback |
Given a list of integers, separate the numbers into four lists based on the following conditions:
1. One list should contain numbers that are divisible by 2.
2. Another list should contain numbers that are not divisible by 2.
3. The third list should contain numbers that are divisible by 2 but also have a digit sum gre... | codefeedback |
Construct an SQL query to find the name, job title, department name, and salary of all employees who have a salary greater than the average salary of their department, ordered by department name and then by salary in descending order. | codefeedback |
Create a responsive webpage using HTML, CSS, and JavaScript that has a navigation bar with a logo, five links to different webpages, and a footer. Implement a dropdown menu in the navigation bar when viewed on smaller screens. Use media queries to ensure that the webpage layout adjusts accordingly on different screen s... | codefeedback |
Build a function to identify a duplicate element in a list, but you are not allowed to use additional data structures such as sets or dictionaries to solve the problem. Additionally, your solution should have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Given a binary tree, write a function that finds the deepest node in the tree. The tree is represented by a root node, which contains a value and references to its left and right child nodes. The function should return the value of the deepest node.
To solve this problem, you can use a breadth-first search (BFS) algor... | codefeedback |
Create a PHP program to print out the frequency of word occurrences in an array, while also considering case sensitivity and excluding any words that contain numbers or special characters.
['Foo', 'bar', 'baz', 'foo', 'Bar', '123', '@#$', 'test1'] | codefeedback |
Calculate the number of weekdays (excluding weekends) from January 1, 2021 to June 30, 2021, excluding any public holidays that fall on weekdays. | codefeedback |
Generate a Python code to check if a given string is a palindrome or not. The code should have a time complexity of O(n) and should not use any additional space other than the input string. Additionally, the code should not use any built-in string manipulation methods or libraries. | codefeedback |
Create a React component to render a 3D pie chart with dynamic data and allow the user to interactively update the chart. The pie chart should also include a tooltip that displays the exact value and percentage of each slice when hovered over. Additionally, implement a feature that allows the user to explode or collaps... | codefeedback |
Create a Python program to find the intersecting element of two lists, ensuring that the program can handle input lists with up to 1000 elements. Additionally, the program should return the intersecting elements in descending order and handle cases where the input lists may contain duplicate elements. The program shoul... | codefeedback |
Design a Data Structure in Javascript to store a list of tasks, where each task has a priority level ranging from 1 to 100, and tasks with higher priority levels should be executed first. Additionally, the Data Structure should support the following operations:
1. `addTask(task, priority)`: Add a new task with the giv... | codefeedback |
Design a Java program to find the maximum of N numbers, where N is a positive integer. Additionally, you need to implement the following features:
1. Validate the user input to ensure that N is a positive integer greater than zero.
2. Prompt the user to enter N numbers one by one and store them in an array.
3. Implemen... | codefeedback |
Write a SQL query to get the top 10 books by rating, considering that the rating is calculated based on a combination of factors such as user reviews, popularity, and sales. Additionally, the query should also take into account the genre of the books, giving higher priority to the top-rated books within each genre.
T... | codefeedback |
Write a shell script that takes input from the user, reverses the string, and prints it on the terminal. Additionally, the script should handle special characters, whitespace, and escape sequences correctly.
#Additional Instructions#
1. Validate the input to ensure it is not empty or too long.
2. Implement error handl... | codefeedback |
Construct a function that will remove all special characters, digits, and whitespace from a given string in JavaScript, while preserving the original order of the remaining characters.
Input: "Hello! My name is John Doe, and I am 25 years old."
Output: "HelloMynameisJohnDoeandIamyearsold" | codefeedback |
Design a program in Python that will count the number of unique words in a sentence, ignoring case sensitivity and punctuation marks. You can assume that the input sentence will only contain alphabetic characters, spaces, and punctuation marks. The program should treat words with different capitalizations as different ... | codefeedback |
Develop a SQL query to find all the records that have been modified within a given time range, and sort them in descending order based on the number of modifications made to each record. The query should also exclude any records that have been modified less than 5 times. | codefeedback |
Create a responsive HTML form that takes 3 inputs: first name, last name, and age. The age input should only accept numeric values and should have a minimum value of 18 and a maximum value of 99. Additionally, the form should have client-side validation to ensure that all fields are filled out correctly before submitti... | codefeedback |
Write an Object-Oriented Python program to find the area of a triangle given the lengths of all three sides.
Provide a piece of erroneous code as a reference to increase misdirection:
```python
class Triangle:
def __init__(self, side1, side2, side3):
self.side1 = side1
self.side2 = side2
s... | codefeedback |
Write a C++ program that counts the number of occurrences of each character in a string without using any built-in functions or libraries. The program should print the characters along with their respective counts in descending order of frequency. | codefeedback |
Write a function to swap the entries in a list. However, you can only use one temporary variable to store the value of one entry while swapping. Additionally, the function should return the modified list instead of modifying it in place.
#Erroneous Code#
```python
def swap_entries(lst, index1, index2):
temp = lst[... | codefeedback |
Construct a function that adds two numbers written in reverse order in JavaScript. The function should also handle cases where the input numbers have leading zeroes and return the sum in reverse order. Additionally, the function should check if the input numbers are valid, ensuring that they are positive integers and h... | codefeedback |
Make the existing JavaScript function asynchronous and use promises instead of callbacks. The function should return a promise that resolves with the result.
function handleData(data) {
return new Promise((resolve, reject) => {
if (typeof data !== 'object') {
reject(new Error('Invalid data type'));
} e... | codefeedback |
What data structure should be used to store a customer's name, address, phone number, and a list of their previous purchases, while also ensuring efficient searching and retrieval of customer information based on their phone number? | codefeedback |
What data structure would be suitable to represent a sparse matrix with billions of columns and rows, where the number of non-zero elements is expected to be less than 0.1% of the total elements? | codefeedback |
Select all rows in a pandas dataframe where at least one value exists in the column named ‘name’, the corresponding value in another column named ‘age’ is greater than 30, and the value in a third column named ‘salary’ is within a certain range, say between 50000 and 100000.
#Reasoning Steps#
1. Iterate through each r... | codefeedback |
Create a function that searches the given sorted list to find a key value and returns its position. The function should have a time complexity of O(log n) and should not use built-in search functions such as index(). Additionally, the function should handle cases where the key value is not present in the list and retur... | codefeedback |
Create a function that returns the longest substring of the string given, where the substring must contain at least two uppercase letters and exactly two digits, with one digit preceding the first uppercase letter and one digit following the second uppercase letter. | codefeedback |
Given a list of integers, write a program to convert it into a list of strings. Additionally, implement the following requirements:
1. Convert all odd integers to strings and leave the even integers as they are.
2. Remove any duplicate integers from the resulting list.
3. Sort the list in descending order based on the... | codefeedback |
Suggest an in-place sorting algorithm for an array that contains both duplicates and unique elements, without using any extra data structures or libraries. The algorithm should have a time complexity of O(nlogn) and should be able to handle large arrays efficiently.
Additionally, the algorithm should be stable, meanin... | codefeedback |
Write a SQL query that finds the TOTAL sales of each product in a given month, calculates the percentage of the total sales for each product in that month, and determines the percentage of sales for each product compared to the total sales in all months. Additionally, the query should only include products that have sa... | codefeedback |
Create a CSS style to display text in italics, but without using the CSS `font-style` property. The style should also include a hover effect that changes the color of the text to red. | codefeedback |
Write a bash script to replace all occurrences of the letter 'a' with the letter 'b' in 'myfile.txt', but only if the letter 'a' is followed by a number between 1 and 9. Additionally, if the number is odd, replace it with the letter 'c', and if the number is even, replace it with the letter 'd'. | codefeedback |
Create a data structure to store all of the prime numbers up to 100 million. Additionally, provide a piece of erroneous code that attempts to check for primality using a faulty algorithm. The erroneous code should introduce a subtle logic error that produces incorrect results for certain numbers. | codefeedback |
Write a Django code to print the name of all the users in the database. Additionally, display the number of posts each user has made. Implement a pagination feature that limits the number of users displayed per page to 10. Allow the user to navigate between pages using next and previous buttons. Also, add a search func... | codefeedback |
Write a SQL query to update the value of column b in the table called a, but only for rows where the value of column a is a prime number and column b is not divisible by 3.
Table name: a
Columns: a, b
Current state of table a:
a | b
1 | 10
2 | 11
3 | 12
4 | 13
5 | 14
6 | 15 | codefeedback |
Given the following array, remove all duplicates and return a new array with the remaining elements. Additionally, sort the new array in ascending order. The input array will not contain any negative numbers and will have a length of at most 100. You must solve the problem in O(n) time complexity. arr = [1, 2, 4, 3, 3,... | codefeedback |
Write a function in C++ to reverse a C-style String, taking into account that the input string may contain special characters and spaces. The reversed string should maintain the original placement of special characters and spaces. Additionally, you are not allowed to use any additional data structures or libraries, and... | codefeedback |
Using variable A, write a code snippet in Java to iterate through an ArrayList of integers and delete all numbers that are both prime and divisible by 3. | codefeedback |
Create a function in Java to check if a given array contains duplicates. The array can contain both positive and negative integers. The length of the array can be up to 1000 elements. The function should return true if there are any duplicate elements in the array, and false otherwise. Additionally, you need to impleme... | codefeedback |
## Given Test ##
Bring the following two variables into the same format:
Variable one: 12.34
Variable two: 21.103
## Extra Challenge ##
Modify the program to handle an arbitrary number of variables in different formats and bring them all into the same format.
### Additional Instructions ###
1. The input for each vari... | codefeedback |
Develop a program in Python to implement a Multiple Linear Regression model.
## Problem Statement ##
Write a Python program to implement a Multiple Linear Regression model to predict the price of a house based on its features such as number of bedrooms, number of bathrooms, and square footage.
## Instructions ##
1. T... | codefeedback |
Read the given input, and write a Python code to create a dictionary which contains unique elements as keys and their corresponding count as values. The input will contain a mixture of strings, integers, and lists. The code should be able to handle any type of input and count the occurrences of each unique element. How... | codefeedback |
Given an array of integers, find all unique triplets that sum up to zero and return the count of such triplets.
Example:
arr = [-1, 0, 1, 2, 2, 3, 4]
In the given array, there are two unique triplets that sum up to zero:
[-1, 0, 1] and [-1, 2, -1]. Therefore, the expected output is 2.
Please write a function that t... | codefeedback |
Given an array of strings, sort the strings in descending order of the number of vowels present in the string. If two strings have the same number of vowels, sort them alphabetically. The array can contain duplicate strings.
array = ["Banana", "Apple", "Orange", "Pineapple", "Grapes", "Cherry"] | codefeedback |
Create a function in Python to modify the given list and remove all strings with length less than three. The function should also remove any strings that contain numbers. The modified list should be sorted in reverse alphabetical order. Additionally, any duplicate strings should be removed from the final list.
mylist ... | codefeedback |
Write a function in JavaScript that takes in a number x and returns all possible pythagorean triplets whose sum is equal to x. The function should return an array of arrays, where each inner array represents a triplet. Each triplet should be in ascending order. Additionally, the function should exclude any triplets whe... | codefeedback |
Write a CSS code to create a responsive navigation menu with the following requirements:
1. The menu should have a horizontal layout.
2. The menu items should be evenly spaced and centered.
3. Each menu item should have a different background color.
4. When hovering over a menu item, its background color should change... | codefeedback |
Write a SQL query which returns rows that have duplicate values in exactly four columns and only if the duplicates are consecutive, and the query should not use the DISTINCT keyword. | codefeedback |
Create a python generator that prints fibonacci numbers from n to 2*n-1, where n is a positive integer greater than 1. The generator should only print the numbers that are divisible by 3 and also contain at least one digit that is a prime number. | codefeedback |
Write a jQuery code to find and display the longest word from a given string. Additionally, if there are multiple longest words with the same length, display all of them.
var str = "This is a sample string.";
#Additional Instructions#
1. Exclude any punctuation marks from the words. Only consider alphabetic character... | codefeedback |
Find the sum of two integers without using + or - signs, and with a time complexity of O(log n), where n is the larger of the two integers. Additionally, the solution must not use any mathematical operations such as multiplication, division, or exponentiation.
a = 123456789
b = 987654321 | codefeedback |
Generate a code to implement a binary search in a sorted array of strings with up to 10 million elements. The array may contain duplicate strings, and the search should return the index of the first occurrence of the target string. The time complexity of the code should be O(log n), where n is the number of elements in... | codefeedback |
Write a HTML code to show a table with 5 columns and 10 rows. Each cell in the table should have a different background color. The background color of each cell should be generated randomly from a predefined set of colors. Additionally, the table should have a border of 2 pixels and each cell should have a padding of 1... | codefeedback |
Using HTML/CSS and JavaScript, construct a web page that generates a random password with the following requirements:
1. The password must be at least 12 characters long.
2. The password must contain at least two uppercase letters, two lowercase letters, two digits, and two special characters.
3. The password must not ... | codefeedback |
Generate a code to find the kth smallest prime number in an unsorted list of positive integers given three inputs (list, k and n).
list = [12, 3, 5, 7, 19]
k = 3
n = len(list)
In this version of the test, the code needs to identify the kth smallest prime number from the given list of positive integers. This requires ... | codefeedback |
Write a query in SQL to list the products from a given supplier, but only include products that have a price greater than $100 and are in stock. | codefeedback |
Given an array of positive and negative integers, find the maximum possible sum of a subarray within the array. The subarray must contain at least two elements and the elements must be consecutive. Additionally, the maximum sum should be achieved in a time complexity of O(n). | codefeedback |
Create a function in Java to generate Fibonacci numbers up to n, but you are not allowed to use recursion or any built-in functions to calculate Fibonacci numbers. Additionally, your function should have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Describe a way to implement quicksort, but also explain how to handle cases where the input array contains duplicate elements. Additionally, discuss the time complexity of your implementation and provide a piece of erroneous code that could potentially break your algorithm. | codefeedback |
Generate a code to throttle a stream of messages that exceeds a set limit of messages within a certain time window. The time window should now be dynamically calculated based on the average frequency of messages received in the past 10 minutes. The code should also be able to handle multiple streams of messages simulta... | codefeedback |
Create a function in Python that takes a list of integers and returns the first three elements whose sum is a prime number. Additionally, provide a piece of erroneous code that attempts to solve the problem but contains a logical error. | codefeedback |
Write an HTML code for a form to submit data. The form should have a maximum character limit of 100 for each input field, and it should validate that the email address provided is in the correct format. Additionally, the form should include a dropdown menu with at least 5 options and a checkbox that must be checked bef... | codefeedback |
Create a new object with the four properties of an employee specified in the given object, ensuring that the employee's name is at least 8 characters long, their salary is a positive integer, their age is between 18 and 60, and their department is one of the following: 'Engineering', 'Finance', 'Marketing', or 'Operati... | codefeedback |
Create a new array containing the square of each element in the given array, but exclude any numbers that are divisible by 3 and also include the square root of the numbers that are divisible by 3.
my_array = [2, 3, 4, 5, 6, 7, 8] | codefeedback |
Print each word in the given sentence in reverse order, without using any built-in string manipulation functions or libraries. | codefeedback |
Print a pyramid of stars that has 10 levels, but each level must have a different number of stars. The number of stars in each level should follow the sequence: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19. | codefeedback |
Complete the following code to delete the item at a given index from a list, but also handle the case where the index is out of range. Additionally, ensure that the program raises a custom exception called "InvalidIndexError" when the index is negative.
index = -2
list_items = [2, 3, 4, 5, 6, 7, 8] | codefeedback |
Create an HTML page with an input box and a button. When the user clicks the button, it should calculate and display the factorial of the number entered in the input box. The solution should handle large numbers efficiently and should not use any built-in factorial functions or libraries. Additionally, the solution sho... | codefeedback |
Create a for loop to iterate through a given list and print the list elements in reverse order. However, the loop should only iterate through half of the list length. If the list length is odd, exclude the middle element from printing.
list_items = [2, 3, 4, 5, 6, 7, 8]
# Expected Output:
8
7
6
5
Explanation:
1. Fin... | codefeedback |
Write a function that takes a string as input and prints each unique letter of the string on a separate line in reverse alphabetical order. The function should ignore any whitespace characters in the string and only consider letters. The function should handle both uppercase and lowercase letters. The function should h... | codefeedback |
Print only the odd numbers from the given list in ascending order. You are not allowed to use any built-in functions or libraries. You must implement your own logic to determine if a number is odd or even. The list can contain up to 1000 elements. Additionally, you are required to do this in a single pass, without stor... | codefeedback |
Write a code that prints each word in a given string on a separate line, ensuring that no word is printed more than once. Additionally, the code should output the words in sorted order based on their frequency of occurrence in the string. | codefeedback |
Correct the syntax error in the following HTML structure and add a CSS class to the outer <div> element. Additionally, dynamically fetch data from an API and display it within the <h1> tag.
<div class="container">
<h1 id="data"></h1>
</div> | codefeedback |
Code an algorithm to find the closest pair of elements in a given array with respect to a given target number. The array will contain at most 10^6 elements and the target number will be within the range of -10^9 to 10^9. You need to find the pair of elements that have the smallest absolute difference with the target nu... | codefeedback |
Write an SQL query to sort the table 'employees' based on their age in descending order. In addition, include a column that calculates the average age of all employees in each row of the result. Only include employees who have been with the company for at least 5 years and have a salary greater than $50,000. | codefeedback |
Write a CSS code to style links in a page with the following requirements:
- The links should have a hover effect that changes the background color, font color, and font weight.
- The links should have a different style when visited, including a different font color, text decoration, and a transition effect.
- The link... | codefeedback |
Create an HTML form in which a user can input text, select multiple options from a dropdown menu, and a button to submit. When the user submits the form, display all the selected options, in addition to the inputted text, in an alert box. The options should be displayed in alphabetical order.
Additionally, implement ... | codefeedback |
Create an HTML page with a heading "Welcome to My Site" and a paragraph below it, stating "This is a personal website showcasing my projects". Additionally, the HTML page should include a navigation bar with links to at least three different sections of the website, and each section should contain a relevant image and ... | codefeedback |
Write an R code to get the names of all uncorrelated columns in a data frame. Additionally, your solution should be able to handle missing values in the data frame and provide a way to specify the desired level of significance for determining correlation. Furthermore, your solution should use a custom correlation funct... | codefeedback |
Given an HTML file, parse the file and retrieve all the elements with a specific tag name. Additionally, check if any of the elements have a specific class attribute with a specific value and if so, print out the class name as well.
Specifics:
- You should be able to handle large HTML files efficiently.
- You should u... | codefeedback |
Create a dynamic web page that displays the company name, logo, and description. Implement functionality to allow the user to change the company name, logo, and description through an input form.
Requirements:
1. The web page should have a header section that displays the company name and logo.
2. The company name sho... | codefeedback |
Create a GPT-3 model to generate text given a seed phrase, with the requirement that the generated text must have a minimum length of 1000 characters. Additionally, ensure that the generated text includes at least 5 paragraphs, each consisting of at least 200 characters. | codefeedback |
Write a JavaScript program to accept user input and store it in a variable. Additionally, the program should validate the user input to ensure it meets the following criteria:
- The input must be a string of at least 10 characters.
- The input must not contain any numbers.
- The input must not contain any special chara... | codefeedback |
Develop a machine learning model to predict the stock price of a company based on historical data. The historical data should include a wider range of features such as volume, market sentiment, economic indicators, and other relevant data sources. Implement advanced preprocessing techniques such as data normalization, ... | codefeedback |
Rewrite the following code using List Comprehension to print the maximum prime number from a list of integers. The code should also check if the maximum prime number is a palindrome. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.