instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Create a Python program for identifying the common elements between two lists. The program should return a list containing all the common elements, without any duplicates, in ascending order. The program should have a time complexity of O(n log n), where n is the total number of elements in both lists. Additionally, th... | codefeedback |
Write a program that takes two integers as input and performs the following operations in the given order:
1. Subtract the second number from the first.
2. Multiply the result by 5.
3. Divide the result by 2.
4. Add 10 to the result.
Display the final result.
Example:
Input:
First number: 8
Second number: 6
Output:
... | codefeedback |
Reverse the given array in-place and return it, but do not use any built-in array reversing functions or methods. The original array should be modified. Additionally, you should solve this problem using a recursive approach instead of using loops or iteration.
[1, 2, 3, 4, 5] | codefeedback |
Create a Java program for solving cubic equations with complex roots. The program should handle both real and complex coefficients. | codefeedback |
Convert the given integer to a 32-bit binary, ensuring that the most significant bit represents the sign of the number (1 for negative, 0 for positive). Additionally, you should implement the conversion function without using any built-in functions or libraries that directly convert integers to binary. | codefeedback |
Write an Angular typescript code to validate a complex input form that includes the following fields:
1. Name: Must be between 3 and 30 characters long and contain only alphabetic characters. Time complexity requirement: O(n)
2. Email: Must be a valid email address. Time complexity requirement: O(n)
3. Password: Must ... | codefeedback |
Convert the following HTML string to a DOM tree using JavaScript. Ensure that the <div> tag can contain multiple levels of nested elements, such as <span>, <p>, and <a>, with each level potentially containing more nested elements. | codefeedback |
Insert n new elements at the beginning of a list, where n is the length of the list. Each new element should be a randomly generated string of length m, where m is a random number between 1 and 10 (inclusive).
Example:
Input: ["a", "b", "c", "d"]
Output: ["x1", "x2", "abcd", "defg", "a", "b", "c", "d"]
Constraints:
-... | codefeedback |
Suggest a code segment to render a greeting message in a terminal window using Python. However, the message should be displayed in a different color than the default color of the terminal, and the color should be specified using the RGB color model. | codefeedback |
Suggest a code segment to generate a random integer in the range of 0 to 1000 using Python, without using any built-in functions or libraries for generating random numbers, and ensure that the generated number is always divisible by 7. | codefeedback |
Suppose a function and a variable are already defined. Write a code statement to assign the value of the variable to the function, but the function must be called recursively until a specific condition is met.
function: my_recursive_function
variable: my_var
The specific condition is that the value of the variable mu... | codefeedback |
Please implement a JavaScript function that toggles a given CSS class on an element with a given ID. The function should also accept an optional third argument, which specifies the delay in milliseconds before the class is toggled. If no delay is specified, the class should be toggled immediately. The function should r... | codefeedback |
Suggest a command-line program in any programming language that checks for any available updates for a package called 'foo' using the package manager 'apt-get' on a Linux system. Additionally, optimize the program to retrieve only security updates for the package.
Note: The program should be able to handle any version... | codefeedback |
Transform this code fragment to use the appropriate data structure and also calculate the frequency of each letter in the word. Additionally, ensure that the solution has a time complexity of O(n) and a space complexity of O(1), where n is the length of the word.
word = "apple"
frequency = [0] * 26
for i in range(len(... | codefeedback |
Write a Nodejs function to print out the ASCII art for a given (input) text. The function should also allow the user to customize the font style, size, and color of the ASCII art. Additionally, the function should support special characters and symbols in the input text and handle multiline text input properly. | codefeedback |
Suggest an approach to debug a complex recursive function written in JavaScript that is not returning the expected result. Additionally, provide a code snippet with multiple logical errors to mislead the candidate during the debugging process. The candidate should identify and fix all the logical errors in order to obt... | codefeedback |
Create a Java class to represent a point (x, y, z) in a three-dimensional space. Implement the following methods:
1. `getX()` and `setX(int x)`: Get and set the x-coordinate of the point.
2. `getY()` and `setY(int y)`: Get and set the y-coordinate of the point.
3. `getZ()` and `setZ(int z)`: Get and set the z-coordina... | codefeedback |
Write a JavaScript function that sorts an array of positive integers in ascending order, using the bubble sort algorithm. The function should also calculate and return the total number of comparisons made during the sorting process. Additionally, the function should validate the input array to ensure it only contains u... | codefeedback |
Create a program that reads in a text file and counts the frequency of each unique word in the file. Display the words and their respective frequencies in descending order. Exclude common words such as "the", "and", "is", etc. from the word count. Additionally, exclude any words that contain special characters such as ... | codefeedback |
Write a Python program that can accept a 2D array and returns the column-wise sum of the given array. The input array will contain n rows and m columns, where 1 <= n, m <= 10^6. The elements of the array will be integers between -10^6 and 10^6.
Example:
Input:
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
Output:
[12, 15, 18]
... | codefeedback |
Generate an HTML page with a table containing all the prime numbers of an array in JavaScript and color the background of each row alternately. The array is [2, 5, 7, 10, 11, 15, 20, 23, 25, 30]. | codefeedback |
Write a C program to print all prime numbers between 1 and 100, excluding those that are divisible by both 3 and 5. Additionally, you must implement a function to calculate the factorial of a given number and use it to find the sum of all prime numbers that are greater than 50. | codefeedback |
Create a query in SQL to find the name, address, and contact information of the customers who purchased a particular product (Mobile Phone) and have spent more than $500 on that product. Additionally, include the total amount spent by each customer on the product and the average price of the product across all purchase... | codefeedback |
Find the index of the smallest odd prime number in an array of positive integers using Java. The array can contain duplicates, and the number of elements in the array can be very large (up to 10^6). The time complexity of the solution should be O(n), where n is the number of elements in the array. The solution should a... | codefeedback |
Create an algorithm in Java to print all the prime numbers between a given range, while minimizing the time complexity as much as possible. Additionally, the algorithm should optimize space complexity by using a memory-efficient data structure. | codefeedback |
Write a SQL query to fetch records from a table where the sum of a specific column, grouped by a certain condition, is greater than a given value. The results should be sorted in descending order based on another column, and only include records that meet an additional complex condition involving multiple columns. | codefeedback |
Create a function in C to replace all occurrences of a given character in a string with another given character. However, you are not allowed to use any string manipulation functions (e.g., strcpy, strcat, etc.) or any built-in functions or libraries.
String1 = "Hello World", Character1 = 'o', Character2 = '*'
Note: ... | codefeedback |
Write a function in JavaScript that selects all elements with class "test" from a given HTML document and returns an array of their inner texts. | codefeedback |
Write a program that replaces all occurrences of a given substring in a sentence while ignoring the case sensitivity. Additionally, remove any leading or trailing whitespaces in the sentence before performing the replacement. The program should output the modified sentence.
For example, if the given substring is 'appl... | codefeedback |
Construct a binary tree using an array representation in Python, and implement the following operations:
1. Insert a value into the tree
2. Delete a value from the tree
3. Find the minimum value in the tree
4. Find the maximum value in the tree
5. Check if a value exists in the tree
Additionally, provide an erroneous ... | codefeedback |
Use the list comprehension feature of Python to create a list of words with length more than 10. Additionally, the words should not contain any vowels. Furthermore, the words should be sorted in descending order based on their length, and if two words have the same length, they should be sorted in alphabetical order. F... | codefeedback |
How can you use an AJAX callback to retrieve data from a web page while also handling error cases, optimizing the performance of the AJAX request, and ensuring that the retrieved data is properly formatted and stored in a database within a specified time limit? | codefeedback |
Write a C++ code to store the marks of multiple students in a multidimensional array, and calculate the average of the marks for each student as well as the overall class average. | codefeedback |
Write a NumPy code snippet to create a matrix of given shape and fill it with a specific pattern. The shape should have at least 3 dimensions and no more than 6 dimensions. The number of elements in the matrix should be greater than 20 and less than or equal to 500. The pattern should be defined as follows: each elemen... | codefeedback |
Write a function to calculate the largest possible number from the given list of integers, considering that the numbers can be negative as well. The function should also handle if the list contains duplicates.
Additional requirements:
1. The function should have a time complexity of O(nlogn), where n is the length of ... | codefeedback |
Use SQL to add a new record to a table, but ensure that the record being added does not violate any constraints defined on the table (e.g., primary key, unique key, foreign key constraints). Additionally, you must implement a trigger that automatically updates a related table whenever a record is added or modified in t... | codefeedback |
Given a string `message` of maximum length 1000, implement a function `function(message)` that returns a reversed version of the input string. The function should also handle cases where the input string contains special characters, numbers, and uppercase letters. Additionally, the function should ignore leading and tr... | codefeedback |
Write a function that takes a given string and its length as input arguments and then prints the string in reverse order. Additionally, the function should remove any duplicate characters from the reversed string before printing it. The function should also return the count of the unique characters in the reversed stri... | codefeedback |
Write a JavaScript code snippet to query a given database table and return only the records that meet the following conditions:
- The 'users' table must have at least 1000 records.
- The 'users' table must have an additional column named 'age' with values ranging from 18 to 60 (inclusive).
- The returned records must b... | codefeedback |
Write a function that takes in a decimal value as input and returns its binary equivalent. The function should have a time complexity of O(log^2 n), where n is the decimal value.
#Explanation#
The original test asked for a time complexity of O(log n), which means the function should be able to convert a decimal value ... | codefeedback |
Create a MySQL database table with four columns: id, message, timestamp, and status. The id column should be the primary key and auto-incremented. The message column should be a text column that can store up to 1000 characters. The timestamp column should store the current date and time whenever a new row is inserted. ... | codefeedback |
Create a program that takes an integer input from the user and prints all the elements from 1 to the input number. However, only print the odd numbers and skip any number that is divisible by both 3 and 5. Additionally, the program should calculate the sum of all the printed numbers and print it at the end. | codefeedback |
Construct an algorithm to solve this coding problem. Given two sorted linked lists, merge the two lists into a single sorted list and return the head node of the merged list. The algorithm should have a time complexity of O(n) and use constant extra space. | codefeedback |
Calculate the area of a square with each side equal to the product of the first 10 prime numbers. | codefeedback |
Generate the list of all prime numbers between 1000 and 2000, and print the product of the first 10 prime numbers found. | codefeedback |
Compute the greatest common divisor of the numbers 345 and 765, but without using the built-in gcd function or any mathematical libraries. | codefeedback |
Emulate the following behavior in CSS:
1. Create a button that is initially hidden.
2. When the button is hovered over, it should show.
3. The color of the button should change randomly based on a random number generated between 1 and 100.
4. The color should be updated every second.
Note: The button should be created... | codefeedback |
Generate a 2D array with 5 rows and 6 columns in Java. Initialize each element of the array with a random integer between 1 and 100. Each row of the array should have at least one element greater than 50. Print the sum of all the elements in the array. | codefeedback |
Produce a SQL query to find the names, ages, and subjects of all students who have a score greater than 95 in at least 3 subjects, ordered by their ages in descending order. Additionally, exclude students who have a score less than 90 in any subject and have taken at least 5 subjects. | codefeedback |
Write a function that takes in a positive integer and determines if it is a prime number. A prime number is defined as a number greater than 1 that has no positive divisors other than 1 and itself. The function should also handle cases where the input number is a decimal, returning false in such cases. | codefeedback |
Outputs the sum of two integer variables only if both variables are positive and the sum is greater than 15.
a = 5
b = 10 | codefeedback |
Please perform data validation on two strings s1 and s2 according to the given conditions on the length, special characters, character sequences, and additional conditions.
s1 = "Hello@world!"
s2 = "tEst123"
Conditions:
1. Both s1 and s2 should be at least 8 characters long.
2. s1 should contain at least two special c... | codefeedback |
Write an HTML page which displays the current time and date in a specific format (e.g. "Monday, January 1, 2022 12:00 PM"). Additionally, the time and date should update automatically every second without refreshing the page.
Increase the difficulty by requiring the use of JavaScript to fetch the current time and date... | codefeedback |
Write a Python function using the Pandas library to filter out the rows with a missing value in the specified column. Additionally, the function should only return the rows where the Age is greater than 20 and the Name is alphabetically ordered in descending order. Furthermore, the function should also check if the row... | codefeedback |
Create a responsive web page that has a button to toggle a navigation bar. The navigation bar should have a drop-down menu with multiple items. When the button is clicked, the navigation bar should smoothly slide in or out of view. Additionally, the navigation bar should be responsive and adjust its layout and styling ... | codefeedback |
Generate a Python generator to produce a sequence of the first N numbers that are greater than or equal to 100 and less than or equal to 1000. The sequence should only include numbers that are divisible by both 5 and 7. | codefeedback |
Create a responsive web page that allows users to input a specific date and displays the corresponding day of the week in multiple languages. The web page should also provide an option to switch between a 12-hour and a 24-hour time format. Additionally, the user should be able to select a specific time zone and the web... | codefeedback |
Create a Python script to find the maximum value of a list containing both strings and numbers. If the list contains any non-numeric elements, they should be ignored while finding the maximum value. The script should also handle nested lists and dictionaries within the input list.
L = [1, 'a', 4, 3, 'b', 6, 'c', [2, 8... | codefeedback |
Write a query in SQL that returns the maximum number for each unique category, but only for orders with a price greater than 100. The query should also exclude any categories that have less than 5 orders with a price greater than 100. | codefeedback |
Prepare a Java method which takes a string as an argument and returns the number of unique words in it. The method should ignore punctuation marks and consider case sensitivity (e.g. "cat" and "Cat" should be considered as different words). The method should also exclude common English stop words such as "the", "and", ... | codefeedback |
Write a code to compare two numbers in python and return the larger number. If both numbers are equal, return the string "Equal". However, you are not allowed to use any comparison operators (e.g., >, <, ==) or built-in functions (e.g., max, min) to solve this problem.
num1 = 5
num2 = 7 | codefeedback |
Write a query in SQL to list the top 3 most expensive items from each category, excluding any items with a price higher than 1000. The result should be ordered by category and then by price in descending order.
TABLE items
item_id INT PK
category VARCHAR
price INT | codefeedback |
Create a Python function called "calculate_correlation" that takes in two parameters, x and y, which are both numerical lists of length n (1 <= n <= 10^6). The function should calculate the correlation coefficient between x and y using the formula:
correlation = (sum((xi - x_mean) * (yi - y_mean)) / (n * x_mad * y_mad... | codefeedback |
Create a Python script that filters a list of words and returns only those with an even length of characters. The script should exclude any words that contain a capital letter and any words that have a vowel as the first or last character. Additionally, the filtered words should be sorted in descending order based on t... | codefeedback |
Design a Python script that takes a large array of integers (size greater than 10,000) and finds the median efficiently. The script should have a time complexity of O(n) or better and should not use any built-in sorting functions or libraries. Additionally, the script should be able to handle arrays containing duplicat... | codefeedback |
Write a function that takes two lists as parameters, and returns a third list, containing the elements that occur on both the given lists. The function should have a time complexity of O(n), where n is the length of the longer list. Additionally, the function should not use any built-in Python functions that directly s... | codefeedback |
Develop a code in JavaScript to sort an array of integers into descending order. Additionally, implement the sorting algorithm yourself instead of using built-in methods or functions. Make sure to handle any edge cases and optimize the sorting algorithm for efficiency. The code should have a time complexity of O(n log ... | codefeedback |
You are given a string and a substring. Output the index of the first occurrence of the substring in the string. The substring should match the entire word, not just a part of it. Additionally, the solution should be case-insensitive. If the substring is not found in the string, return -1.
#Example:
string = "Hello w... | codefeedback |
Create a function in R which creates a histogram to visualize a given vector and set the bin size. Additionally, calculate and display the mean, median, mode, and standard deviation of the vector.
vector = c(2, 3, 5, 6, 12, 12, 15, 17, 18, 20, 22, 25, 26, 26, 26, 28, 30, 35, 36, 37)
bin_size = 5 | codefeedback |
Design an algorithm in C# which searches for a given element in a sorted array. However, instead of using a binary search approach, implement a recursive algorithm that uses a quaternary search approach. The algorithm should return the index of the element if found, and -1 if not found.
A = [2, 3, 4, 10, 14, 20, 26, 3... | codefeedback |
Design an algorithm in Python that takes an array of classmates' age and returns the median age. If there are an even number of ages, return the average of the two middle ages. If there are an odd number of ages, return the middle age.
ages = [10, 9, 12, 14, 11]
Additional requirements:
1. The algorithm should have a... | codefeedback |
Draft an HTML page with a table that contains five columns and ten rows. The table should have alternating background colors for each row. Each cell in the table should contain a randomly generated number between 1 and 100. Additionally, implement a functionality where clicking on a cell will highlight the entire row t... | codefeedback |
Write a SQL query to find the top 3 most populated cities in each state, excluding the cities with a population less than 100,000. Additionally, the query should return the average population density of each state based on the top 3 cities. The population density should be calculated as the population divided by the ar... | codefeedback |
Code a function in C that takes an integer array and its size as two arguments and returns the median of these numbers. Additionally, provide a piece of erroneous code as a reference to increase misdirection.
The median should be calculated by finding the middle element of the sorted array. If the size of the array is... | codefeedback |
Write a function to count the number of times a given character is found in an input string, but only count the occurrences of the character if it is surrounded by a pair of parentheses and the parentheses are not nested within another pair of parentheses. Ignore any occurrences of the character that are not surrounded... | codefeedback |
Write a SQL query to sort a table based on the values in five columns: 'gender', 'age', 'salary', 'date_of_birth', and 'position'. The sorting should be done in the following order:
1. First, sort the table based on the values in the 'gender' column in ascending order.
2. For rows with the same 'gender' value, sort t... | codefeedback |
Write a JavaScript code to fetch the current weather of any city and display the temperature in both Celsius and Fahrenheit.
In addition to fetching the weather data, also include error handling in case the API call fails or the city name is not found.
Furthermore, implement a feature that allows the user to input mu... | codefeedback |
Create a function that takes in a list of characters from the Lord of the Rings and returns an array of their corresponding nicknames. The function should have a time complexity of O(n), where n is the number of characters in the input list. The nicknames should be returned in alphabetical order. The input list will al... | codefeedback |
Implement a function in Python to compute the median of an array containing floating-point numbers, without using the built-in sorted() function or any other external library. The array may contain up to 1 million elements. The time complexity of your solution should be O(n log n). | codefeedback |
Given an array of numbers [20, 40, 60, 80, 100], write a JavaScript function that prints the first, second, and third smallest elements in the array in ascending order. The function should have a time complexity of O(nlogn) and should not use any built-in sorting functions. Additionally, the function should handle dupl... | codefeedback |
Write a JavaScript function that takes an array of integers as input and returns a new array that contains only the prime numbers from the original array. Store the resulting array in the local storage.
Note: A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. | codefeedback |
Write a query in SQL to calculate the total cost of orders placed in the month of May, where the order must have at least 5 items, the total cost must be greater than $1000, and the customer must have made at least 3 previous orders. | codefeedback |
Create an HTML form to capture the first name and last name of the user. Add client-side validation to ensure that the first name is at least 2 characters long and the last name is at least 3 characters long. Additionally, the form should display an error message if the user submits the form without entering both the f... | codefeedback |
Deploy a dynamic e-commerce website on AWS using only serverless components. Ensure that the website is highly scalable and can handle a large number of concurrent users. Implement authentication and authorization using AWS Cognito, with the ability for users to sign up, log in, and manage their profiles. Additionally,... | codefeedback |
Create an SQL query to find all the records in the 'customers' table that have a name that starts with 'John' and have made at least 3 purchases in the past month. Additionally, exclude any records where the customer's email address ends with '@gmail.com'. | codefeedback |
Using HTML and CSS, create a table containing 1000 rows and 1000 columns. The table should have alternating background colors for each row. Additionally, each cell should have a border and a hover effect that changes the background color. Ensure that the table renders quickly and efficiently, without any noticeable lag... | codefeedback |
Edit the code to convert the string "cat" to "dog" using a recursive function. However, you should only be allowed to use a single recursive call and no other loops or conditional statements.
String str = "cat";
public static String convertString(String str) {
if(str.length() == 0) {
return "";
}
... | codefeedback |
Make an AJAX request to get the list of items from a server.
Endpoint URL: http://example.com/items
However, the response from the server is in a compressed format (e.g., gzip or deflate). Decompress the response on the client-side before processing the data.
In addition, the server randomly sends the response in di... | codefeedback |
Write a Python 3 script to print out all the words in the string 'I love coding' in reverse order, ensuring that each word is printed in reverse order and contains only lowercase letters. | codefeedback |
Edit the code to delete all elements with value 6 from the array and return the resulting array. However, you are not allowed to use any additional data structures or modify the size of the original array.
int arr[] = {2, 4, 6, 6, 8, 10} | codefeedback |
Change the following SQL query so that it only returns rows from the 'employees' table where the salary is higher than 50000 and the employee's job title is either 'Manager' or 'Director', and the employee has been in the company for more than 5 years.
SELECT * FROM employees WHERE salary > 50000 AND (job_title = 'Mana... | codefeedback |
Given a vector x containing N elements, where N is a positive integer less than or equal to 100, write a Python function to compute and return the sum of the elements in x. The elements in x can be positive or negative integers, and they may contain duplicates. Additionally, the function should handle any possible inte... | codefeedback |
Compute the prime factors of a given positive integer, but also ensure that the solution runs in O(sqrt(n)) time complexity, where n is the given positive integer. | codefeedback |
Create a secure and scalable REST API in Node.js with authentication, rate limiting, and support for pagination and sorting. Additionally, implement role-based access control to restrict certain API endpoints to specific user roles. | codefeedback |
Create a CSS style to make all the links within a specific section of the webpage with the class "content" have the color purple and a hover effect that changes the background color to yellow. Additionally, make the style only apply to links within nested elements within the "content" section, up to a depth of 3 levels... | codefeedback |
Modify a given paragraph by replacing all instances of the word "the" with the word "a" and all instances of the word "is" with the word "was". The modified paragraph should still make grammatical sense and maintain the original meaning. For example, if the original paragraph is "The cat is on the mat", the modified pa... | codefeedback |
Write a code to check if an element is present in a nested array. If the element is found, print its index position in the outer array and inner array. If the element is not found, print a message stating that the element is not present.
array = [['apple','dog','cat'],'mouse','ball']
element = 'cat' | codefeedback |
Write a JavaScript function to filter all numbers in an array and return a new array containing only the prime numbers.
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
#Erroneous Code#
```javascript
function filterPrimeNumbers(arr) {
let primeNumbers = [];
for (let i = 0; i < arr.length; i++) {
if (arr[i] === 1) {
... | codefeedback |
Create a Wordpress theme from scratch that includes a custom post type called "Portfolio" and a custom taxonomy called "Skills". Additionally, create a page template that displays all the portfolio items grouped by skill and allows the user to filter the items based on multiple skills.
To increase the difficulty, you ... | codefeedback |
Create an HTML page containing a link that redirects the user to another page, when clicked. Additionally, implement a feature that records the number of times the link has been clicked and displays it on the redirected page. The redirected page should also display a countdown timer that starts at 10 seconds and update... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.