instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write an SQL query to retrieve the top 5 scores in a table that contains scores for all players. Additionally, the query should display the player's name, the date of their score, and the game in which they achieved it. The scores should be sorted in descending order and only scores from the last 30 days should be cons... | codefeedback |
Given the data structure below, write a function to print out all the elements in the array, but with the constraint that the function should have a time complexity of O(n^2), where n is the length of the array.
const arr = [1, 2, 3, 4, 5];
Write the function such that it first sorts the array in ascending order, and... | codefeedback |
Create a function in JavaScript which can receive and store user inputs, validate the input to ensure it meets specific criteria, and provide appropriate error messages for invalid inputs. The specific criteria for validation are as follows:
1. The input must be a string.
2. The input must be between 5 and 10 characte... | codefeedback |
Create a database table called 'Employees' with fields such as employee_id, name, age, email, etc. Implement a function to perform CRUD operations (Create, Read, Update, Delete) on the 'Employees' table using an Object-Relational Mapping (ORM) framework of your choice. Ensure that the function is capable of handling a ... | codefeedback |
Create a class in JavaScript called "Person" with the following properties: "name" (a string) and "age" (a number). Implement two methods for the class: "greet" (which prints a greeting message including the person's name) and "celebrateBirthday" (which increments the person's age by 1).
Requirements:
1. The "greet" m... | codefeedback |
Write a JavaScript program to find the sum of an array of numbers using a recursive function. The function should take an array of numbers as input and return the sum of all the numbers in the array. The input array can have a maximum length of 10000. The time complexity of the solution should be O(n), where n is the l... | codefeedback |
Write a function to calculate the power of two numbers (base^exp) using only basic arithmetic operations (addition, subtraction, multiplication, and division) and without using any built-in exponentiation or logarithmic functions. Additionally, your function should be able to handle negative exponents and fractional ex... | codefeedback |
Construct and execute a SQL query to select fields from the following table, where the email addresses must be in a specific format and the domain of the email address must be one of the specified options.
Table: student
Fields: firstname, lastname, email
The email addresses must be in the format "firstname.lastname@d... | codefeedback |
Create a function in Python for sending an email using the SMTP protocol. Your function should validate the email address and password provided by the user, and only allow sending the email if the authentication is successful. Additionally, the function should handle any errors or exceptions that may occur during the e... | codefeedback |
Implement a function that checks if a given number, n, is a prime palindrome. A prime palindrome is a number that is both a prime number and a palindrome.
To solve this problem, follow these steps:
1. Check if the number is less than 2. If it is, return False, since prime numbers are greater than 1.
2. Check if the n... | codefeedback |
Explain the function and importance of a variable in programming, and provide an example of how variables are used in a specific programming language. Additionally, discuss the concept of variable scoping and provide an example that demonstrates the different scopes within a programming language of your choice. | codefeedback |
Name and describe a feature of the JavaScript Date object that allows you to format the date string in a specific timezone while also accounting for daylight saving time changes. Additionally, provide an example of how this feature can be used to handle time conversions between different time zones in a single line of ... | codefeedback |
Implement the update function in Java for a circular queue data structure. The update function should only allow updates to be made if the queue is not full, and it should throw an exception if the queue is already at maximum capacity. Additionally, the update function should only allow updates to be made if the elemen... | codefeedback |
Create three classes in Python which inherits from a parent class called **Shape**.
The parent class **Shape** should have the following attributes:
- `name` (string) - representing the name of the shape (maximum length of 20 characters)
- `color` (string) - representing the color of the shape (maximum length of 10 ch... | codefeedback |
Create a Java function that takes in two integers as parameters and returns their sum as a double. The function should also check if the sum exceeds a certain threshold, which is defined as the maximum value of a long integer. If the sum exceeds the threshold, the function should throw an exception with a custom error ... | codefeedback |
Using an array, write a Python script that prints the sum of the numbers from 0 to 100, excluding any multiples of 3. Your script should also exclude any numbers that are divisible by both 2 and 5. | codefeedback |
Generate an HTML page to display a list of names in alphabetical order. The names to be displayed should be obtained from a database, where each name should have a corresponding unique ID. The HTML page should also include a search bar, where users can search for specific names. The names should be displayed in a visua... | codefeedback |
Create a JavaScript function to convert a given temperature in celsius to its equivalent in fahrenheit, but without using any arithmetic operators. Additionally, the function should not use any conditional statements (if-else, switch) or loops (for, while). | codefeedback |
Create a list comprehension in Python to generate the first 10,000 prime numbers. | codefeedback |
Create a function in Python to identify if the inputted number is prime or not. Additionally, create a function to find the nth prime number.
You should also handle invalid inputs, such as negative numbers or non-integer inputs, and raise appropriate exceptions.
Please provide a piece of erroneous code as a reference... | codefeedback |
Change the following code to create a new string without spaces and all letters in uppercase, using only a single line of code. The code must also reverse the order of the characters in the resulting string.
string = "Hello World" | codefeedback |
Summarize the given article about the rise of artificial intelligence and its impact on the job market and society in one sentence, while also providing the source of the article. Additionally, ensure that the summary is less than 20 words long and includes at least one statistical data point. | codefeedback |
Create a JavaScript class called "Person" that represents a person's information. The class should have the following properties: name (string), age (number), and hobbies (array).
The class should have the following methods:
1. A method called `introduce` that prints out the name and age of the person.
2. A method cal... | codefeedback |
Write HTML code that creates a table with the following specifications:
1. The table should have 5 rows and 5 columns.
2. The table should have a header row that spans all columns and displays the text "Table Header".
3. Each cell in the table should have a unique ID attribute in the format "cell-{row}-{column}", where... | codefeedback |
Create a C++ Program to reverse the words of a string while maintaining the original order of the words. Additionally, handle cases where there are leading or trailing spaces in the string and multiple spaces between words. Implement the program without using any string manipulation functions or libraries. | codefeedback |
Given an array of integers and a target value, write a Java program to determine whether this array contains two elements with the given target sum. The array may contain negative numbers and duplicates. The target sum can be any integer value. Return the indices of the two elements that add up to the target sum. If th... | codefeedback |
Write a code to extract data from a password-protected PDF document, where the password is unknown. Additionally, the code should handle PDF documents with multiple pages and extract data from all the pages. | codefeedback |
Implement a stable sorting algorithm for the following array of objects:
Object[] array = {new MyClass(23), new MyClass(10), new MyClass(4), new MyClass(15), new MyClass(66), new MyClass(28), new MyClass(11)};
where MyClass is a custom class with an integer attribute.
The sorting algorithm should have a time complexi... | codefeedback |
Create a MySQL query to select all the employees who have made at least 100 sales, sorted by the total sales amount in descending order. The query should also include the employee's average sales amount, the total number of sales made by each employee, and the percentage of sales contributed by each employee compared t... | codefeedback |
Write a SQL query to find out all the cities that have the most expensive houses, but exclude any cities that have a population less than 1 million and are located in a country with a GDP per capita below $20,000. | codefeedback |
Edit the following code to return a Promise in the getMessage() function. The Promise should resolve with the fullName after a random delay between 1 and 5 seconds. Additionally, the getName() function should be modified to accept a callback function as an argument and call that function with the fullName after a delay... | codefeedback |
Create a function in JavaScript that takes a string as an argument, counts the number of occurrences of a given character, and returns the count as well as the indices of each occurrence in an array. Additionally, the function should handle cases where the input string is empty or the given character is not found in th... | codefeedback |
Write a Dockerfile for an Nginx server that includes a custom configuration file, sets up SSL/TLS encryption using a self-signed certificate, and automatically renews the certificate using a cron job. | codefeedback |
Create a responsive HTML and CSS layout to display a grid of books with their author, title, description, and a thumbnail image.
Book 1: Author - John, Title - The Catcher in the Rye, Description - “The Catcher in the Rye is a 1951 novel by J. D. Salinger.”, Thumbnail - image1.jpg
Book 2: Author - Jane, Title - Sens... | codefeedback |
Build a function in PHP that converts a string into ASCII code. The function should handle strings of any length and should have a time complexity of O(n), where n is the length of the string. However, the function should also have a space complexity of O(1), meaning that it should not use any additional data structure... | codefeedback |
Create a program to generate random passwords of variable length (between 8 and 16 characters) consisting of letters, numbers, and special characters. The password must meet the following requirements:
- At least 3 uppercase letters
- At least 3 lowercase letters
- At least 3 numbers
- At least 3 special characters
Th... | codefeedback |
Create a program to search for a specific word in a document and return the index position of the first occurrence. The program should handle multiple documents and allow the user to input the document and word to search. The program should also handle case sensitivity, so that "words" and "Words" are considered differ... | codefeedback |
Compose a SQL query to display the department(s) with the highest average salary of employees, where the average salary must be greater than $100,000 and the department must have at least 10 employees. Additionally, exclude any departments that have employees with a salary less than $50,000. | codefeedback |
We want to display a random number between 1 and 10 using Python. Write a program for that, ensuring that the same number is not displayed consecutively. Additionally, the program should keep track of the count of each number displayed and print the count at the end. | codefeedback |
Construct a method in Java to calculate the weighted average of an array of numbers, where each number is multiplied by a corresponding weight from a separate array of weights. The method should also handle cases where the array of numbers and the array of weights have different lengths. Additionally, the method should... | codefeedback |
Write an SQL query to select the employees who have worked for more than 10 years, have a salary higher than the average salary of all employees, and belong to a specific department (e.g. "Sales").
Additionally, consider the following constraints:
1. Exclude employees who have worked for more than 20 years.
2. Include... | codefeedback |
In JavaScript, explain the difference between var, let, and const in terms of variable scoping and how they behave in functions. Provide examples to illustrate your explanation. Additionally, discuss the concept of hoisting and how it relates to var and let. | codefeedback |
Write a SQL query to calculate the average age of customers who have purchased items from a store, while also excluding any customers who have made a purchase in the last 30 days. Additionally, include only customers who have made at least 5 purchases in the past year. | codefeedback |
Code a function that prints out the characters of a string in reverse order, starting from the last character. However, you are not allowed to use any built-in functions or methods that directly reverse the string.
#Erroneous Reference#
str = "Hello World!"
def reverse_string(string):
for i in range(len(string), ... | codefeedback |
Write a JavaScript code snippet to filter an array to retain only the strings in the array that start with "A" and end with "e". Additionally, the filtered array should be sorted in ascending order based on the length of the strings.
Array: ["Apple", "Banana", "Orange", "Apple Pie", "Avocado", "Alone"]
Time Complexit... | codefeedback |
## Problem Statement ##
Develop a web service to convert a temperature value from Fahrenheit to Celsius. The input temperature should be provided as a string. Return the converted temperature as a float, rounded to two decimal places.
## Signature ##
```python
def convert_temp(temperature: str) -> float:
__input_... | codefeedback |
Find the greatest number from an array that may contain both positive and negative numbers. If the array is empty, return None. You may assume that the array will only contain integers.
Example:
arr = [41, 77, -56, 99]
Output: 99 | codefeedback |
Create a UI Automation test that validates the text field is populated with the value "Hello World!" within a time limit of 1 second. The test should also ensure that the text field is not editable during the validation process. Additionally, the test should handle scenarios where the text field is not visible or disab... | codefeedback |
Create an SQL query to select only the rows from a table where the second column is not empty, contains at least one uppercase letter, and the first column values are in descending order. | codefeedback |
Create an initialization script for a database that includes the following requirements:
1. Create a table called "users" with the following columns:
- id (integer)
- name (string)
- email (string)
- password (string)
- created_at (timestamp)
- updated_at (timestamp)
2. Create a table called "posts"... | codefeedback |
Construct a multi-threaded application in Python to read and calculate the sum of a list of numbers, where each number is represented as a string and can be up to 10^100 in length. The list can have up to 10^6 numbers. The application should be able to handle numbers in scientific notation as well. The sum should be ca... | codefeedback |
Your job is to implement a sorting algorithm from scratch. You are not allowed to use any built-in sorting functions or libraries. Additionally, your algorithm should have a time complexity of O(nlogn) and a space complexity of O(1). | codefeedback |
Create an HTML document to display the following text:
"Welcome to our website!"
However, the text must be displayed in a unique font that is not commonly used in web design. Additionally, the text should be formatted as a heading with a font size of 30 pixels and a different font color than the default.
To make it ... | codefeedback |
Code a function to compute the difference between two dates, but the input dates are provided in a non-standard format: "MM-DD-YYYY". Additionally, the function should handle leap years correctly when calculating the difference between the dates. The function should return the difference in years, months, days, hours, ... | codefeedback |
Write a regular expression pattern to find all the words which begin with a digit, but do not end with a digit, and contain at least one uppercase letter. | codefeedback |
Create a SQL query to retrieve the name, address, contact number, and total spending of the customers who have made at least three purchases in the last month and belong to the "Gold" tier, ordered by their total spending in descending order. | codefeedback |
Design an algorithm in Python to detect palindrome strings with the following constraints:
- The algorithm must have a time complexity of O(n^2), where n is the length of the input string.
- The algorithm must not use any built-in string manipulation functions (e.g. reverse(), join(), etc.).
- The algorithm must ignore... | codefeedback |
Write a code in Java to convert any string to camel case format, while also removing any consecutive duplicate characters in the string. Additionally, the code should ignore any duplicate characters that are surrounded by a specific substring "ignore", and these characters should not be removed. The output string shoul... | codefeedback |
Using Python, create a program that prints out the prime numbers between 0 and 100 in descending order. | codefeedback |
Parse a deeply nested JSON string that contains arrays and objects, ensuring that the parsing algorithm has a time complexity of O(n) and a space complexity of O(1). The JSON string may include additional data types such as boolean, null, and numeric values, and must be parsed without the use of any external libraries ... | codefeedback |
You are working on a project that involves storing and manipulating a large list of numbers. As the data set is quite large and needs to be accessed in a specific order, you need to choose the most suitable data structure to efficiently store and access these numbers. Additionally, you need to ensure that the data stru... | codefeedback |
Implement a queue data structure that supports the following operations:
1. `enqueue(item)`: Add an item to the end of the queue.
2. `dequeue()`: Remove and return the item at the front of the queue.
3. `peek()`: Return the item at the front of the queue without removing it.
4. `isEmpty()`: Check if the queue is empty.... | codefeedback |
Create a class for a basketball team that tracks the performance statistics of each player, including points scored, assists, rebounds, steals, and blocks. Additionally, the class should have a method to calculate the overall team performance based on these statistics, taking into account the individual player's contri... | codefeedback |
Perform sentiment analysis on a given set of movie reviews using Python, considering multiple sentences instead of just one. The movie reviews are as follows:
1. The cinematography and special effects were exceptional, but the plot was weak.
2. The acting in this movie was top-notch, especially by the lead actor.
3. De... | codefeedback |
Given a data set, calculate the median using Python. The input list can contain duplicate elements and can have a maximum length of 100. The algorithm should have a time complexity of O(nlogn) and should not use any built-in libraries or functions to calculate the median. | codefeedback |
Create a query in PostgreSQL to display all the records in a given table, where each record has a column called 'salary' that stores the salary amount for each employee. However, you need to display the records in descending order of the 'salary' column. Additionally, you should only display records where the 'salary' ... | codefeedback |
Write a MySQL query to find all the customers who have placed an order in the last 30 days, have ordered at least 3 times in total, and have a total order amount of more than $500. | codefeedback |
Given the following employee table:
```
employee
+------+--------+-------+
| id | name | age |
+------+--------+-------+
| 1 | John | 25 |
| 2 | Mary | 28 |
| 3 | John | 30 |
| 4 | David | 22 |
+------+--------+-------+
```
Write an SQL query to retrieve the names and ages of all e... | codefeedback |
Write a function to calculate the factorial of a given number n using recursion. | codefeedback |
Implement the depth-first search algorithm in a programming language of your choice. Your implementation should take a graph represented as an adjacency list and a starting node, and return the order in which the nodes were visited during the search. Additionally, analyze the time complexity of your implementation and ... | codefeedback |
Create a React component that displays a grid layout of items. Each item should have the following properties:
- id: a unique identifier for the item (string)
- name: the name of the item (string)
- price: the price of the item (number)
- imageURL: the URL of the image representing the item (string)
The component shou... | codefeedback |
Write a method in Swift to capitalize the first letter of each word in a given sentence. The sentence may contain punctuation and multiple spaces between words.
However, in addition to capitalizing the first letter of each word, you need to:
1. Remove any leading or trailing spaces in the sentence.
2. Ensure that all ... | codefeedback |
Write a CSS structure to style a div element with the following requirements:
- The background color should be a gradient that transitions from 'red' to 'blue' in a radial pattern.
- The div element should have a border with a thickness of 2 pixels and a color that alternates between 'black' and 'white' for each side.
... | codefeedback |
Create a program to detect a negative number in an array of numbers. However, you are not allowed to use any comparison operators (e.g., <, >, <=, >=, ==) to check for negativity. You can only use mathematical operations to determine if a number is negative.
You are also not allowed to use any iteration or recursion. ... | codefeedback |
Explain the concept of fuzzy logic and provide an example. In your explanation, also discuss the advantages and disadvantages of using fuzzy logic compared to traditional binary logic. Additionally, provide a detailed analysis of a real-life problem that can be effectively solved using fuzzy logic, including the reason... | codefeedback |
Design and implement a highly secure and scalable automated login system that can handle multiple users and ensure secure authentication. Consider the following additional requirements:
1. User Management:
- The system should support registration of new users with a valid email address and mobile number.
- Each ... | codefeedback |
Develop an API that returns a list of students and their ages, sorted in descending order of their ages. The API should be able to handle large amounts of data efficiently, with a time complexity of O(nlogn) or better. Additionally, the API should be able to filter the list of students based on specified criteria such ... | codefeedback |
Write a pseudo-code algorithm that implements the following polynomial equation using Horner's method:
3x^5 + 2x^4 - 7x^3 + 6x^2 - 4x + 1. Your algorithm should be able to handle input values for x ranging from -10 to 10. | codefeedback |
Search for all usernames that contain the substring "John" at the beginning of the string in the database. The search should be case-sensitive and should return both exact matches and partial matches. The database contains millions of records, so the algorithm should be efficient and not have a time complexity higher t... | codefeedback |
Design an algorithm for the following use case:
Given two arrays A and B of the same length, determine whether there is a pair of indices (i, j) such that A[i] is a prime number and B[j] is a Fibonacci number. | codefeedback |
Write a program to determine the number of islands in a given map of Scotland. The map is represented by a 2D matrix where 0's represent water and 1's represent land. An island is formed by connecting adjacent lands horizontally or vertically. In this version, an island is considered to be any connected region of land ... | codefeedback |
Design the algorithm to perform a depth-first search on a given binary tree and return the sum of all the nodes in the tree. Additionally, the algorithm should keep track of the maximum value node found during the search. | codefeedback |
Generate all possible permutations of the given array of numbers, where each permutation must contain exactly two odd numbers and one even number. The original array may contain duplicate numbers, but the permutations should not have any duplicates.
numbers = [1, 2, 2, 3, 4]
(Note: In the original test, there was no ... | codefeedback |
Write a recursive function that takes an input number N and calculates the sum of all prime numbers between 1 and N, considering the following additional constraints:
1. The function should only use iterative methods to check for prime numbers.
2. The function should not use any built-in prime number checking function... | codefeedback |
Create a sorting algorithm for an array that only needs 1 iteration and has a time complexity of O(nlogn).
**Additional Instructions:**
- The sorting algorithm should be implemented in a function named `customSort`.
- The input array can contain positive and negative integers.
- You can assume that the input array wi... | codefeedback |
Use regular expression to remove special characters from any given string and then sort the resulting string in alphabetical order. The special characters to be removed are defined as any non-alphanumeric characters (i.e. not letters or numbers).
my_string = 'Hi There! Welcome.@' | codefeedback |
Debug the following code for finding the median of three numbers, but you are not allowed to use any conditional statements (if, elif, else) or any comparison operators (>, <, ==). You can only use mathematical operations and functions. Additionally, you are not allowed to use any built-in functions for sorting or find... | codefeedback |
Given a string, write a code that counts the number of alphabets in it, ignoring any punctuation marks, special characters, and spaces. The code should also handle uppercase and lowercase letters as separate entities. Additionally, the code should only consider the English alphabet. The code should also check for dupli... | codefeedback |
Create a program to detect a loop in a linked list and return the starting node of the loop. The program should have a time complexity of O(n) and a space complexity of O(1).
In addition to detecting the loop, the program should also remove the loop from the linked list. | codefeedback |
Implement a class called "Person" with the following requirements:
1. The class should have private variables for name, age, and address.
2. The class should have public getter and setter methods for all the variables.
3. The name should only accept a string with a length between 5 and 20 characters.
4. The age should... | codefeedback |
Create an array of 1000 random integers between -1000 to 1000 and print only the prime numbers in descending order. | codefeedback |
Write a SQL query to retrieve data from three tables with similar columns. Additionally, you should order the results by the length of the name in descending order and only return the records where the address is in a specific set of cities ('New York City', 'Los Angeles', 'Chicago', 'Miami', 'Seattle').
Table1
| id ... | codefeedback |
Explain the concept of polymorphism in object-oriented programming and provide an example of how it can be implemented in a real-life scenario. Additionally, describe the advantages and disadvantages of using polymorphism in software development and discuss its impact on code readability and maintainability. | codefeedback |
Design an algorithm to add two given binary numbers with the following constraints:
- The time complexity of the algorithm should be O(log n), where n is the length of the longer binary number.
- The space complexity of the algorithm should be O(1), i.e., the algorithm should not use any additional data structures othe... | codefeedback |
Create a new C++ class with a constructor and destructor that also implements a custom copy constructor and overloaded assignment operator. Additionally, the class should have a member function that performs a deep copy of its data members.
The class should have the following data members:
- An integer array of size 1... | codefeedback |
Classify the given sentence using the Bag-of-Words approach, and also determine the sentiment of the sentence. Extract the important keywords from the sentence by tokenizing it into individual words and removing stop words. Create a Bag-of-Words representation by counting the frequency of each word. Perform sentiment a... | codefeedback |
Given a string, return the length of the longest run of consecutive uppercase letters. A run is defined as a sequence of consecutive uppercase letters. For example, in the string "AaaAbbCcDdd", the longest run is "AA" with a length of 2. | codefeedback |
Change the following code to a yield statement so that it can be used as a generator. Additionally, modify the code to only generate the Fibonacci sequence up to a given number N. However, the code should also handle cases where N is not a positive integer and return an appropriate error message.
def fibonacci_generat... | codefeedback |
Create a class called "MathOperations" with the following methods:
1. "get_sum": This method takes in two numbers as input and calculates their sum. However, instead of using the "+" operator to add the numbers, you must implement your own algorithm for addition using only bitwise operators. You are not allowed to use... | codefeedback |
Write a Python function that takes two lists as input and returns a new list containing the common items between the two lists. The function should handle lists of any length and the items in the lists can be of any data type.
Additionally, the function should also handle nested lists and return the common items in a ... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.