instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a query with window functions in PostgreSQL to calculate the average salary per department, including only those departments where the average salary is higher than a certain threshold value. Additionally, display the highest paid employee in each department along with their salary. | codefeedback |
Create a SQL database schema for storing customers, their payments, and their payment history. Each payment history should include the payment ID, customer ID, amount, date, and a description of the payment. Additionally, include a table for storing the payment methods available to customers. Implement a trigger that u... | codefeedback |
Create a JavaScript object literal for a student with properties (name, age, grade, and school) and a method called "calculateGPA" that calculates the student's GPA based on a given array of grades and corresponding credits. Each grade is represented by a letter (A, B, C, D, or F) and each credit is a positive integer.... | codefeedback |
Update the following Java code to print the difference between two dates in decades, years, months, weeks, days, hours, minutes, and seconds.
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
public class DateTime {
public static void main(String[] args) {
LocalDateTime dateTime1 = L... | codefeedback |
Write a SQL statement to update the age of a customer with a specific ID. Customer_id = 24, Age = 30. However, before updating the age, you need to check if the customer's current age is less than 30. If it is, then update the age to 30. If the current age is already 30 or greater, do not update the age. Additionally, ... | codefeedback |
Rewrite the following code snippet to improve readability and optimize the calculation of factorials by implementing a recursive function.
#Updated Test#
Implement a recursive function called "calculate_factorial" that takes an integer input 'x' and returns the factorial of 'x'.
The factorial of a number 'x' is the p... | codefeedback |
Complete the following javascript code to perform a task.
const items = [
{ company: 'A', date: '02-09-2019' },
{ company: 'B', date: '18-04-2019' },
{ company: 'C', date: '03-12-2019' },
{ company: 'A', date: '29-07-2018' },
{ company: 'D', date: '01-01-2020' },
];
// Complete code here
// You need to sor... | codefeedback |
Create a MySQL query that finds customers who made a payment of more than $100, have not made any refunds in the last 30 days, and have made at least 5 purchases in total. | codefeedback |
Create a component in React for displaying a responsive header with two buttons. The header should be fixed at the top of the page and should have a minimum height of 60 pixels. The buttons should be aligned vertically and horizontally centered within the header. The header should also have a background color of #33333... | codefeedback |
Create a Migration Script in Node.js for creating a table for customers with the following columns:
1. customer_id (primary key) - this column should be an auto-incrementing integer to uniquely identify each customer.
2. first_name (string) - this column should store the first name of the customer.
3. last_name (str... | codefeedback |
Given a Python list of integers, write a program to convert all odd numbers greater than 10 to strings and all even numbers less than or equal to 10 to floats. The resulting list should have the same order as the original list. Additionally, the program should remove any duplicate elements from the list before performi... | codefeedback |
Create a multi-step HTML form for inputting user details including name, age, email, and phone number.
In the first step of the form, validate the name field to ensure it only accepts alphabetic characters and is between 2 and 30 characters long.
In the second step of the form, validate the age field to ensure it onl... | codefeedback |
Modify the following code to make it more efficient by using a while loop. Additionally, implement a binary search algorithm to find the position of a target number in a sorted list of integers. The binary search algorithm should have a time complexity of O(log n) and should be able to handle a list of up to 1 million ... | codefeedback |
Suggest an elegant way to print out a list of numbers in reverse order without using a loop in Python. The solution should have a time complexity of O(1) and should not use any built-in functions or methods for reversing the list.
lst = [1, 2, 3, 4] | codefeedback |
Suggest an alternative for the following code snippet which is faster and less memory intensive, while ensuring that the resulting pairs are in ascending order and contain only prime numbers. Additionally, the alternative should use a maximum of O(1) additional memory.
arr = [2, 3, 5, 7]
result = []
for i in range(len... | codefeedback |
Given a hash table, write a program to print the keys and values in reverse sequence. If the value is a string, capitalize the first letter of each word before printing. Additionally, sort the keys in descending order based on their lengths.
data = {
"FirstName": "john",
"LastName": "doe",
"Age": 25,
"... | codefeedback |
Implement a function that takes 2 numbers as parameters and returns the greatest common divisor of both numbers. The function should not use any built-in library or function for finding the greatest common divisor. Additionally, the function should be able to handle large numbers efficiently.
Furthermore, the function... | codefeedback |
Classify each word in this sentence into its specific part of speech: noun, verb, adjective, adverb, pronoun, preposition, conjunction, interjection, or proper noun. Proper nouns must be capitalized. | codefeedback |
Suggest a cleaner and more concise way to implement the following code snippet, while also handling the case where the target is not found. Additionally, provide a piece of erroneous code as a reference to increase misdirection. Your solution should have a time complexity of O(n), where n is the length of the nums list... | codefeedback |
Write a Python function called `sum_of_lists` that takes in a list of lists as a parameter and returns the sum of all the elements in the input lists. The input list of lists will always contain integers.
The function should have the following specifications:
- Input: a list of lists `lists` containing integers.
- Out... | codefeedback |
Write a code snippet that checks whether a number is odd or even. The code should handle negative numbers, decimals, and fractions. It should also return an error message if the input is not a number, and should only use bitwise operators for the odd/even check. | codefeedback |
Edit this piece of Python code to implement a function that finds the median of a list of numbers. The function should return the median value. If the list has an even number of elements, the median should be the average of the two middle values. Your implementation should have a time complexity of O(n^2) or better and... | codefeedback |
Given a string sentence, convert it into camelCase. In camelCase, each word begins with a capital letter and all spaces between words are removed. The program should also handle sentences with punctuation marks, multiple consecutive spaces, and numbers. | codefeedback |
Explain what a stack overflow is, how to try to avoid it, and provide a code example demonstrating the implementation of a stack data structure in a programming language of your choice. Additionally, your implementation should include error handling for stack overflow situations, where the program should gracefully han... | codefeedback |
Given a list of integers, write a Python program to create a new list that contains the square of every element in the original list. Additionally, for each square, if it is divisible by 3, append the string "divisible by 3" to the new list; if it is divisible by 5, append the string "divisible by 5" to the new list; i... | codefeedback |
Make a program to return the longest palindrome word in a given list of strings. A palindrome word is a word that reads the same forwards and backwards. The program should handle cases where multiple palindrome words have the same maximum length and return all of them. The input list may contain words with different ca... | codefeedback |
How can you use object serialization and encryption to implement a distributed messaging system, where multiple nodes communicate with each other asynchronously, maintain a consistent state across the network, and ensure secure data transmission? | codefeedback |
Implement an algorithm with Big O notation of O(n log n) that sorts an array of integers in ascending order. Additionally, the algorithm should only use a constant amount of extra space and should handle arrays of size up to 10^6. | codefeedback |
Find the surface area of a cube with a side length of 6 cm, but only using a recursive function. Additionally, you must implement the recursive function using only a single parameter. | codefeedback |
Using MySQL, find the top 10 customers who have made the most orders, considering only orders placed within the last 6 months. Additionally, display the total number of orders made by each of these top 10 customers, the average order value for each customer, and exclude any customers who have placed orders with a total... | codefeedback |
Check if the given statement is syntactically correct by verifying the validity of each word and the overall sentence structure, taking into account the rules of grammar and punctuation. Additionally, ensure that the statement follows a specific sentence structure pattern, where the subject comes before the verb and th... | codefeedback |
Create a function that takes two strings and outputs the number of similar characters in both strings. The function should be case-sensitive and consider spaces as characters as well.
For example:
String 1: "Coding"
String 2: "debugging"
The function should return 3, as both strings have the letters 'd', 'i', and 'g' ... | codefeedback |
Using MongoDB, update the product price for a specific product, but only if the product is in stock, the new price is within a certain range, and the product has not been updated within the last 24 hours. If the product is not in stock, the new price is outside the range, or the product has been updated within the last... | codefeedback |
Write an SQL query to list the names of the top 3 students who scored the highest average marks across all exams, while excluding any students who have scored below 60% in any individual exam. | codefeedback |
Design a database schema for a social media platform that can handle millions of users and their posts efficiently. Include the necessary tables, relationships, and indexes to optimize performance and ensure scalability. Additionally, design the schema in a way that supports real-time notifications for users when they ... | codefeedback |
Insert a record into a database table named 'customers' with the following values. The table has the following columns:
- ID: integer (unique, non-negative)
- Name: string (no more than 50 characters, contains only letters and spaces)
- Age: integer (non-negative)
- Address: string (no more than 100 characters)
The r... | codefeedback |
You need to code a program that prints out the nth Fibonacci number. However, the program should have a time complexity of O(log n) and use matrix exponentiation to calculate the Fibonacci number. n=10 | codefeedback |
You're asked to generate a unique list from a given list of duplicate integers. However, the unique list should maintain the order of the first occurrence of each integer in the input list. Additionally, you are not allowed to use any built-in functions or libraries to solve the problem.
input_list = [1, 1, 2, 3, 3, 3... | codefeedback |
Your program needs to edit an existing string by replacing certain words with another word. However, the replacement must be case-insensitive. The input string may contain punctuation marks and special characters. Additionally, you should handle situations where the replacement word itself contains punctuation marks or... | codefeedback |
Code a function that takes an array of positive integers and returns the sum of the prime numbers in it.
Example:
input_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
output: 17
Note: The function should only consider positive integers greater than 1 as prime numbers. The function should also check for prime numbers in a m... | codefeedback |
Create a JavaScript code snippet to check the validity of a credit card number. The credit card number should meet the following criteria:
1. It should have exactly 16 digits.
2. The first digit should be between 4 and 6.
3. The sum of all digits (excluding the last digit) should be a multiple of 10.
4. The digits in t... | codefeedback |
Create a Java program to compute the total price of a customer's order based on item prices and quantities, with the additional constraints and enhancements:
1. The program should validate the input for item prices and quantities. It should only allow the user to input positive integer quantities for each item and pos... | codefeedback |
Write a program that takes an input array of positive integers with a length of at least 10. The program should swap all even and odd elements in the array, ensuring that the order of the elements remains the same. The program should only use a single loop to iterate through the array and should not use any additional ... | codefeedback |
Develop a program that picks a random item from a given list of strings. However, the program should not use the built-in random function or any external libraries. Additionally, the program should ensure that each item in the list has an equal probability of being selected. The program should have a time complexity of... | codefeedback |
Write a Python program to calculate the sum of the first 100 prime numbers. | codefeedback |
Write a SQL query for creating a table named "users" with columns for "name", "email", "age", and "address". Additionally, add a constraint to ensure that the email column only accepts unique values. Implement a trigger that automatically updates the "address" column with the value "Unknown" whenever a new user is inse... | codefeedback |
Write an SQL query for finding the average salary of employees in a table whose age is greater than 25, their last name starts with the letter "S", and they belong to a specific department.
#Additional Requirements#
1. The department must have at least 5 employees.
2. The average salary should only consider employees ... | codefeedback |
Write a class in Python for representing a rectangle. This class should store the length and width of the rectangle as positive integers, and be able to compute its area. Additionally, the class should have a method to compute the perimeter of the rectangle. The rectangle should also have a method to check if it is a s... | codefeedback |
Generate a function that takes a given list of strings and orders them by their lengths in descending order. The function should also handle cases where multiple strings have the same length, in which case they should be ordered alphabetically. The function should have a time complexity of O(n log n), where n is the le... | codefeedback |
Your program needs to read a matrix of integers and then print out the sum of each row and each column separately. The matrix can have variable dimensions and can contain both positive and negative numbers. Additionally, you need to find the maximum and minimum values in each row and each column. The program should als... | codefeedback |
Create a boolean variable in Java, initialized to false. Implement a method called `toggleBoolean` that takes in the boolean variable as a parameter and toggles its value. The method should have a time complexity of O(1) and should not use any additional space. Additionally, the implementation should handle concurrent ... | codefeedback |
Write a CSS code to display a web page with a centered container of width 800px and a height of 400px. The container should have a border radius of 10px and a background color gradient that starts from #FFC0CB at the top left corner and ends with #FF69B4 at the bottom right corner. The text inside the container should ... | codefeedback |
Convert the date 1972-05-18 12:00 PM (in the UTC timezone) to a UNIX timestamp. Handle any potential errors that may occur during the conversion and provide an appropriate error message. | codefeedback |
Implement a recursive algorithm to find the nth Fibonacci number. The Fibonacci sequence is defined as follows: the first two numbers in the sequence are 0 and 1, and each subsequent number is the sum of the previous two numbers.
Write a function called fibonacci that takes an integer n as input and returns the nth F... | codefeedback |
Generate a program in Go for printing the first 1000 prime numbers, using a concurrent approach. The program should utilize a maximum of 10 concurrent goroutines for improved efficiency. | codefeedback |
Edit the following C program so that it prints the factorial of a number. However, you are not allowed to use any loop structures (such as for, while, or do-while) to calculate the factorial. Additionally, you are not allowed to use any recursion or built-in mathematical functions to calculate the factorial. You must f... | codefeedback |
Write a program that takes a positive integer input from the user and calculates the sum of all prime numbers up to that number. The program should check for prime numbers using the Sieve of Eratosthenes algorithm. | codefeedback |
Write code to calculate statistical measures such as Standard Deviation, Median, and Mean from a given set of numbers.
The input array can contain up to 1 million numbers and the numbers in the array can range from -10^9 to 10^9.
Your solution should have a time complexity of O(n) and space complexity of O(1), where ... | codefeedback |
How would you convert a binary number to decimal in JavaScript while also checking for any invalid input and accounting for negative binary numbers?
#Explanation#
In order to convert a binary number to decimal, we need to perform the following steps:
1. Start by checking if the input is a valid binary number.
2. Itera... | codefeedback |
Classify a given string as either a palindrome, a word or a phrase.
Write a function named "classify_string" that takes in a string as a parameter and returns a string classification.
A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward, disregarding spaces... | codefeedback |
Create a JavaScript object that keeps track of event data such as time, attendees, location, and additional details. The object should also include methods to add and remove attendees, update the event time and location, and retrieve the event details.
Requirements:
1. The object should have a property to store the ev... | codefeedback |
Format a given decimal number as a percent value, considering that the decimal number can have up to 4 decimal places. The program should also handle negative decimal numbers and round the final result to the nearest whole number. | codefeedback |
Given a string and an integer n, reverse the substring starting from the nth character and ending at the (2*n)th character. If there are less than (2*n) characters after the nth character, reverse the substring until the end of the string. Return the modified string.
Python. | codefeedback |
Implement a function that retrieves the value of a specific key from a given dictionary, while ignoring the built-in dictionary methods. The function should handle nested dictionaries as well. Additionally, the function should only return the value if the key is present in the dictionary, otherwise it should return Non... | codefeedback |
Edit the following program so that it prints out the result of x multiplied by y, but you are not allowed to use the multiplication operator or any built-in functions related to multiplication. Additionally, you must implement your own function for addition and use it to calculate the result.
x = 7
y = 5
def add(a, b)... | codefeedback |
Using PHP, define a function that multiplies two numbers and returns the result as a string with the decimal places rounded to the nearest hundredth. Additionally, ensure that the function can handle negative numbers and has error handling in case of invalid inputs. | codefeedback |
Write an HTML page with a header that displays your name and an image of yourself. The image should be dynamically loaded from an external URL, and the header should have a hover effect that changes the background color. Additionally, the image should be surrounded by a border that has a gradient effect. | codefeedback |
Write a JavaScript code that prints out the prime numbers between 0 and 100,000. | codefeedback |
Given an array of integers and a target value, write a function to find the index of the first occurrence of the target value in the array. If the target value is not found in the array, return -1.
However, the catch is that you cannot use any looping constructs (e.g., for loop, while loop) to iterate through the arr... | codefeedback |
Write a recursive function in Python to calculate the nth term of the Fibonacci sequence, but this time, you are not allowed to use the 'if' statement or the 'else' statement in your code. | codefeedback |
Generate an SQL query to get all the columns of the table "Users" where the column "age" is greater than or equal to 18 and less than or equal to 25, and the column "gender" is 'Male'. Additionally, the query should return the average of the "salary" column for these users. | codefeedback |
Implement a program that solves the traveling salesman problem (TSP) using a brute-force approach and returns the shortest tour possible. The program should handle up to 12 cities and must run in less than 10 seconds. Additionally, the program should use dynamic programming to optimize the algorithm and reduce the over... | codefeedback |
Using React, create a component that displays a greeting with the current time. Additionally, implement a feature that allows the user to change the displayed time format between 12-hour and 24-hour formats. However, the component should update the time dynamically every second, without causing any noticeable performan... | codefeedback |
Create a CSS rule for a class called "main-text" which sets the font weight of the text to bold, the font color to blue, and the font size to 16 pixels. Additionally, the rule should apply only to paragraphs with the class "main-text" that are contained within a div with the class "container". However, the font weight ... | codefeedback |
Create a class for a 2D vector in Java that has the following functionalities:
1. Ability to initialize the vector with x and y coordinates.
2. Ability to retrieve the x and y coordinates of the vector.
3. Ability to set the x and y coordinates of the vector.
4. Ability to calculate the magnitude of the vector.
5. Abil... | codefeedback |
Calculate the total distance traveled by an object with a given initial velocity, acceleration, and time interval. The time interval is a non-integer value and must be rounded to the nearest hundredth decimal place.
However, due to a bug in the program, the acceleration is not constant and changes every second. The a... | codefeedback |
Design an algorithm to print out the prime numbers between 1 and 100 that are also palindromic numbers, but excluding single-digit palindromic prime numbers. | codefeedback |
Design an algorithm to traverse a binary tree in level-order and print the nodes at each level in reverse order, while also keeping track of the number of nodes at each level. Additionally, calculate the average value of the nodes at each level and print it along with the reversed node values. | codefeedback |
Design a class to hold calendar date-related information, including the ability to perform various operations on dates such as addition, subtraction, and comparison.
The class should have the following attributes:
- Year: an integer representing the year.
- Month: an integer representing the month.
- Day: an integer ... | codefeedback |
Create a program in Python that takes two strings as input and determines if they are anagrams of each other. The program should also check if the anagram pairs are palindromic. The program should output the count of palindromic anagram pairs found.
string1="listen";
string2="silent";
For example, for the given input... | codefeedback |
Update the following HTML page so it displays a form with the following specifications:
- The form should contain a text input field for the user's name.
- The form should contain a dropdown select field for the user's gender, with options for "Male," "Female," and "Other."
- The form should contain a checkbox input fi... | codefeedback |
Convert the number to a string, but only using a recursive function. The input number can be any integer, positive or negative. The function should handle both positive and negative numbers recursively. | codefeedback |
Using HTML, CSS, and JavaScript, code a responsive navigation bar that includes dropdown menus and a search bar. The navigation bar should be sticky and remain visible when scrolling. The dropdown menus should display on hover and have smooth animations. The search bar should have auto-complete functionality and provid... | codefeedback |
Develop a function in Rust to print the prime factors of a given number.
Number: -15 | codefeedback |
Create a JavaScript function that takes in an array and an element as input. The function should traverse the array and return true if the element exists in the array, and false otherwise. Additionally, if the element exists in the array, the function should return an array containing all the indices at which the eleme... | codefeedback |
Construct an object-oriented program to print out the numerals from 1 to 10 in a specific pattern, where the program must use at least three classes and implement multiple levels of inheritance. Additionally, introduce a runtime error in one of the classes to test the candidate's debugging skills. | codefeedback |
Use Java to create a constructor to set the values of instance variables num1 and num2. Additionally, add a method to the class that calculates the sum of num1 and num2 and returns the result. However, the constructor should also validate that num1 and num2 are both positive integers and throw an exception if either va... | codefeedback |
Create a function in Dart to generate a series of random numbers within a specified range.
Start: -1000
End: 1000
The function should check if the generated numbers are divisible by 3, divisible by 5, and divisible by 7, and return the count of numbers that satisfy all three conditions. Additionally, the function shou... | codefeedback |
Develop a Java program to input a string and reverse the order of words while ignoring any numbers and special characters in the input. The program should also ensure that the reversed words are in uppercase and that the reversed sentence starts with a capital letter and ends with a punctuation mark. Additionally, the ... | codefeedback |
Please implement a function `htmlToJSON(html: str) -> str` that takes a given HTML string as input and returns the corresponding JSON structure as a string. The HTML string may contain nested tags and attributes.
Example HTML string:
```html
<html>
<head>
<title>Example Website</title>
</head>
<bod... | codefeedback |
Compute the sum of all prime numbers between 1 and 1,000,000. | codefeedback |
Write a Python program that takes a string input from the user and checks if it is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward.
In addition to the original requirements, the program should also:
1. Ignore any non-alphanumeric characte... | codefeedback |
Create a class in Java to store the information about a user, with the following requirements:
1. The user's first name should be stored as a string and must be at least 3 characters long.
2. The user's last name should be stored as a string and must be at least 3 characters long.
3. The user's email address should be... | codefeedback |
Write a code snippet to display the name and age of the oldest person in a list called 'people', where the age is a floating-point number rounded to the nearest integer. The list should not contain any duplicate names, and the names should be displayed in alphabetical order. Additionally, the code should handle cases w... | codefeedback |
Implement a function in C++ that takes in an array of integers and returns a new array with the same integers but in reverse order. You are not allowed to use any additional data structures or built-in functions. | codefeedback |
Create a function in JavaScript to find the longest substring in a given string without repeating characters. The function should also handle cases where the input string contains special characters and numbers. Additionally, the function should return the length of the longest substring found. The function should be i... | codefeedback |
How to create a responsive HTML page with a dynamic navigation menu using JavaScript, where the navigation menu items are generated dynamically based on a JSON data source? Additionally, the navigation menu should change its appearance based on the user's interaction, such as highlighting the current active page and di... | codefeedback |
You are asked to create an array of N random prime numbers between 1 to M, where N is a positive integer and M is a positive integer greater than 10. | codefeedback |
Create a new array 'b' from array 'a' containing only prime numbers. Additionally, the new array 'b' should be sorted in descending order. The input array 'a' should contain at least 100 elements.
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ...] | codefeedback |
Please update the following JavaScript code to use object-oriented programming and implement a more complex calculator with additional functionalities.
Requirements:
1. Create a Calculator class with the following properties:
- number1: a number representing the first operand.
- number2: a number representing th... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.