instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Generate a square matrix of size N (where N is an odd number between 3 and 11) using randomly generated numbers between -100 and 100, where the sum of each row and each column is a prime number. Additionally, ensure that the sum of each diagonal (both left-to-right and right-to-left) is also a prime number. | codefeedback |
Create a function "avg_grade" that takes a list of grades and returns the average of the grades, but with a time complexity of O(1) and without using any built-in functions or libraries. The grades in the list will always be integers ranging from 0 to 100. Additionally, the function should handle cases where the list o... | codefeedback |
Retrieve the location of the 3rd occurrence of the letter 'o' in a given string, but you cannot use any string manipulation functions or methods.
String: "hello world" | codefeedback |
Write a SQL query to drop multiple columns from an existing table while keeping a backup of the dropped columns in a separate table.
Table Name: "Customers"
Column Names: "first_name", "last_name", "email"
Backup Table Name: "Customers_Backup"
Backup Column Names: "backup_first_name", "backup_last_name", "backup_email" | codefeedback |
Write an SQL query to return the top 3 most frequently used keywords from the table, excluding any keywords that have less than 10 occurrences, and order them by the number of occurrences in descending order. | codefeedback |
Make a function "convert_time" that would convert seconds to minutes, hours, and days. The function should also include an additional constraint where it should only accept positive integer values for the seconds parameter. Additionally, the function should check if the converted time is within a specific range, such a... | codefeedback |
Generate a function "capitalize" in JavaScript to capitalize the first letter of every word, but exclude the words "a", "an", "the", "and", "but", "or", "for", "nor", "on", "at", "to", "from", and "by" from being capitalized. The function should also handle special characters and punctuation marks within words and main... | codefeedback |
Implement a function to print the Fibonacci series up to the nth term, but also print the sum of the prime numbers in the series. | codefeedback |
Write a Python code to generate a random password of 15 characters containing a mix of uppercase letters, lowercase letters, numbers, and special characters. Additionally, ensure that the password contains at least two uppercase letters, two lowercase letters, two digits, and two special characters. | codefeedback |
Create a frequency chart that tracks the occurrence of each unique word in a given text document. The frequency chart should be implemented using a dictionary data structure in Python. Additionally, optimize the solution to have a time complexity of O(n), where n is the length of the text document. | codefeedback |
Write a function in your preferred programming language that converts a singly linked list into a doubly linked list. The function should have the following signature: `Node* convertToDoublyLinkedList(Node* head)`.
Additionally, modify the function to handle the case where the linked list may contain cycles. If a cycl... | codefeedback |
Write a Python program to print all possible combinations of the given list, where each combination consists of a different number of elements from the original list, and the elements in each combination are in ascending order. Additionally, ensure that the program does not include any duplicate combinations. | codefeedback |
Write a Python program to check if a given string is a palindrome, without using any built-in string reversal functions or libraries. The program should ignore spaces and punctuation marks. The time complexity should be less than O(n^2). | codefeedback |
Write a JavaScript function that returns the first 500 prime numbers greater than 1000.
#Difficulty Increase Reasoning#
By increasing the starting point of prime numbers to be greater than 1000, the difficulty of the programming test question is increased. This requires the implementation of a more optimized and effic... | codefeedback |
Calculate the determinant of a 4x4 matrix, but now you must implement the calculation without using any built-in matrix operations or libraries, and you are not allowed to use recursion. | codefeedback |
Parse the following HTML code and store the data in a Python dictionary. The HTML code may include nested elements and attribute values. Your solution should handle nested elements and correctly store attribute values in the dictionary. Additionally, handle cases where the HTML code includes self-closing tags. | codefeedback |
Create an array of 10 randomly generated prime numbers between 0 and 100, but ensure that no prime number is repeated in the array. | codefeedback |
Write an SQL query with an inner join clause to retrieve the name, age, and email of users who have placed orders in the last 7 days, ordered by their age in descending order. Include only users who are older than 25, have placed at least 3 orders, and have a valid email address that ends with "@domain.com". | codefeedback |
Write a SQL query to find out the shopping category of the product with id 12345, but exclude any products that have a price higher than $100. Additionally, the query should also return the total number of products in the same shopping category and the average price of those products, while also grouping the results by... | codefeedback |
Write a program that compares the time complexity of accessing elements in a linked list and an array, and determines which data structure is more efficient for a given number of elements. The program should also calculate the average time required for accessing elements in each data structure and provide a recommendat... | codefeedback |
Identify the error in the following function:
Replace all spaces in a string with a given character and count the number of replacements made, but do not use any built-in string methods. | codefeedback |
In Java, write a method that reverses an array of integers in place without using any additional data structures. The time complexity of the solution should be O(n) and the space complexity should be O(1).
Reference Erroneous Code:
```java
public static void reverseArray(int[] arr) {
int length = arr.length;
f... | codefeedback |
In Java, write a method that wraps a given string into a paragraph with each line no longer than the given number of characters. Additionally, the method should remove any leading or trailing white spaces from each line of the paragraph before returning it. The method should handle the case when the given string contai... | codefeedback |
Write a Bash script to print the sum of all prime numbers between 0 and 1000. | codefeedback |
Create a program in Python to compute the sum of two numbers, but with the following constraints:
- The input numbers must be entered as strings and converted to integers before computing the sum.
- The program must be able to handle decimal numbers as input.
- The program should also check if the input numbers are wit... | codefeedback |
Complete the following Javascript code to filter out all numbers divisible by 3 and less than 10, and then multiply each remaining number by 2.
const numbers = [1,2,3,4,5,6,7,8,9];
const result =
#Erroneous Reference Code#
const result = numbers.filter(num => {
if (num % 3 == 0 && num < 10) {
return num;
}... | codefeedback |
Classify the following code as a part of a machine learning model
The following code is for a random forest model which predicts whether a customer will churn based on their demographic information:
class RandomForest:
def __init__(self, n_estimators=100, max_depth=None, min_samples_split=2):
self.n_estima... | codefeedback |
Create a function that increments a given number by 1, but the function should only use bitwise operations and cannot use any arithmetic operations. Additionally, the function should have a time complexity of O(1) and should not use any loops or conditional statements. | codefeedback |
Create a Python function that takes a matrix of numbers as input and returns a list of the top k rows with the highest sum of absolute differences between consecutive elements.
Additional requirements:
- The input matrix can have an arbitrary number of rows and columns.
- The function should handle missing values (Non... | codefeedback |
Write a function that generates a dictionary mapping each Keytype with a description of "What it is". The Keytype can be any string consisting of letters, numbers, and special characters. The function should also handle the case where multiple Keytypes have the same description. Additionally, the function should valida... | codefeedback |
Update the given function `reverse_string` to reverse the input string `s` without using any built-in functions or methods that directly reverse the string. The solution should have a time complexity of O(n) and reverse the string in-place without using any additional data structures. The solution should correctly hand... | codefeedback |
Update the existing code to have a shape of (8,8) when an array of size (2,2) is reshaped. The reshaped array should be filled with the values from the original array repeated multiple times if necessary.
#Erroneous Code#
```python
import numpy as np
def reshape_array(arr, shape):
try:
reshaped_arr = np.r... | codefeedback |
Generate an HTML table with three columns and five rows. Each cell in the table should contain a randomly generated number between 1 and 100. Additionally, the table should have alternating background colors for each row, starting with a light gray color for the first row. Finally, the table should have a border around... | codefeedback |
Construct a SQL query to select all records from a table called "employees" where the salary is greater than 8000, the employee has been with the company for more than 5 years, and the employee's job title is "manager". | codefeedback |
Convert the following nested JSON object to a .csv table. Make sure to handle the nested structure correctly.
JSON object:
{
"name": "John Doe",
"age": 35,
"job": "Software Engineer",
"address": {
"street": "123 Main St",
"city": "San Francisco",
"state": "CA"
},
"education": {
"degree": "B... | codefeedback |
Compose a query in MySQL to filter records from a table where the name contains "John" and the age is greater than 30, and the email address ends with ".com". | codefeedback |
Write an SQL query to get the employee details with the highest salary, excluding employees whose salary is above a certain threshold, have been employed for less than a specific duration of time, and whose job title is not in a specific list of job titles. | codefeedback |
Complete the following Node.js code to return 'true' if the input is a valid email address.
A valid email address must meet the following requirements:
1. The local part (before the @ symbol) must be between 1 and 64 characters long and can contain alphanumeric characters, dot (.), underscore (_), or hyphen (-).
2. Th... | codefeedback |
Create a content aggregator application in Python that only aggregates and displays content from a specific set of RSS feeds related to a niche industry. Additionally, the application should allow users to filter and search for specific keywords within the aggregated content, and should also provide an option to sort t... | codefeedback |
Suggest code to check if an object has a given property and its value is equal to a specific value. The object can have nested properties and the code should be able to handle multiple levels of nesting.
For example, consider the following object:
object = {
id: 1,
name: 'John',
address: {
street: '123 Main ... | codefeedback |
Parse the following text and extract all the numbers. This text contains the numbers 10, 20, and 30. However, the text may also contain numbers written in words such as "twenty-five" or "one hundred and fifty". Additionally, the text may contain numbers with decimal points or fractions, such as "3.14" or "1/2". Make su... | codefeedback |
Write a JavaScript function that calculates the factorial of a given number and returns the result as a string with the thousands separator.
Note: The factorial of a number is the product of all positive integers less than or equal to that number. For example, the factorial of 5 is 5 * 4 * 3 * 2 * 1 = 1 | codefeedback |
Show how to find the mean of three numbers in Java. However, you must not use any arithmetic operators such as +, -, *, or /.
int x = 3;
int y = 4;
int z = 5;
// Erroneous code provided for misdirection
int mean = (x + y + z) / 3; // Erroneous code to make candidates think they can use arithmetic operators
System.... | codefeedback |
Write a script in Python that will find the average of a list of numbers. However, the list may contain both integers and strings. Your script should handle this situation by excluding any strings from the calculation and considering only the numbers in the list. The script should also handle cases where the list conta... | codefeedback |
Compose a python function to find the maximum element in a 2-dimensional array, but the array can contain negative numbers as well. Additionally, the function should only consider the maximum element within each row, and return a list of the maximum elements for each row.
array = [[2, 4, 7, 1], [8, 12, 9, 5], [-3, -5,... | codefeedback |
Code a function that takes a list of strings and checks if it is ordered lexicographically in reverse order, considering only the last two characters of each string. If a string has less than two characters, it should be considered as 'zz'.
list_of_strings = ['novel', 'coding', 'algorithm'] | codefeedback |
Create a function in Java that will take an integer as a parameter and return the sum of the square roots of all prime numbers from 1 to the input number.
#Difficulty Increase Explanation#
In the given test, the task was to find the sum of the square roots of all numbers from 1 to the input number. By changing the req... | codefeedback |
Write a function in React to handle a form submission. The form should have at least three input fields and all fields should be required. Additionally, the form should only be submitted if all input fields pass a validation check. The validation check should ensure that the first input field contains only letters, the... | codefeedback |
Calculate the weighted precision, recall, and F1 score of the following machine learning model, with the weights assigned as follows:
- Actual class 1 has a weight of 3
- Actual class 0 has a weight of 2
Actual = [1, 0, 0, 1, 1]
Predicted = [1, 0, 1, 0, 0] | codefeedback |
Write a PHP script to check if a given string contains only lowercase letters and no numbers, special characters, or whitespace. Additionally, the script should have a time complexity of O(n) and should not use any built-in PHP functions or regular expressions. | codefeedback |
Create an HTML page that contains a table with the following headers: Employee ID, Name, Age, Department, and Salary. Populate the table with at least ten rows of data, each representing an employee. The employee information should include a unique employee ID, name, age, department, and salary. The table should have a... | codefeedback |
Reverse a string in place, but without using any additional data structures or built-in functions. The string should be reversed in groups of 2 characters, and the characters within each group should be reversed as well. The input string will always contain an even number of characters.
word = 'hello world' | codefeedback |
Implement the bubble sort algorithm to sort an array of integers in ascending order. The input array should contain at least 10 integers and at most 1000 integers. Each integer in the array should be within the range of -1000000 to 1000000. You cannot use any built-in sorting functions or libraries. The sorted array sh... | codefeedback |
Create a React component that displays a form with two text input fields. The component should also include a submit button that is disabled until both input fields have at least 6 characters. Additionally, the component should include client-side validation to ensure that the input fields only contain alphanumeric cha... | codefeedback |
Write a function that takes two parameters, which are both positive integers, and will return the maximum of the two. Additionally, the function should also handle the scenario where both parameters are equal, and in this case, it should raise a custom exception indicating that the numbers are equal. | codefeedback |
Implement a nested for loop that iterates for the given 2-dimensional array and prints out the corresponding element on each iteration, but this time the elements should be printed in reverse order.
array: [['apple', 'banana'], ['cherry', 'grape'], ['orange', 'kiwi']]
Note: The nested for loop should iterate through b... | codefeedback |
Implement a function to search for an element in a BST and return the number of comparisons made during the search.
root:
5
/ \
3 8
/ \ / \
2 4 6 9
key: 3
Constraints:
- The BST can have up to 10^6 nodes.
- The keys in the BST are unique.
- The function should have a time compl... | codefeedback |
In the rewritten code, replace the input function with a try-except block to handle specific exceptions, such as ValueError and TypeError, and prompt the user to enter a positive integer number greater than 100. Additionally, add a condition to check if the entered number is divisible by 7. The program should also prin... | codefeedback |
Write a function that takes two integers as input and returns their product. However, you are not allowed to use the multiplication operator (*) or any built-in multiplication functions in your solution. Additionally, you are not allowed to use any loops or recursion in your solution. | codefeedback |
Suggest a completion for the following code to check if the given string is a palindrome. The solution should not use any built-in string manipulation functions.
```
def is_palindrome(s):
"""
Check if the given string is a palindrome.
Parameters:
s (str): The string to be checked.
Returns... | codefeedback |
Implement the bubble sort algorithm for a doubly linked list. However, you are not allowed to use any additional data structures or modify the original linked list. You can only swap the values of the nodes. Additionally, you must ensure that the algorithm has a time complexity of O(n^2), where n is the length of the l... | codefeedback |
Create a C++ program to output the Fibonacci Sequence up to a specified number of terms, where each term is the sum of the two previous terms. The program should prompt the user to enter the number of terms and then display the Fibonacci Sequence. Additionally, implement error handling to validate the user input and di... | codefeedback |
Suggest a completion for the following code to generate a random string of the given length from a given set. The generated string should have at least one uppercase letter, one lowercase letter, one digit, and one special character (!@#$%^&*()-_=+[]{};:'",.<>/?).
length = 10
charset = 'abcdefghijklmnopqrstuvwxyzABCDEF... | codefeedback |
In the given code, add an environment variable called `PYTHON_VERSION` that should be used to set the desired version of Python. The code should first check if the `PYTHON_VERSION` environment variable is set. If it is set, the code should use the specified version of Python. If it is not set, the code should use the d... | codefeedback |
Rewrite the following C code as assembly language:
int a = 5, b = 6, c;
c = a + b;
Additional Constraints:
1. You are not allowed to use any arithmetic instructions directly.
2. You must use bitwise operations and logical operations to perform the addition.
3. You should not use any temporary variables to store interm... | codefeedback |
Evaluate the given expression, where the numbers are represented as strings and the operators are represented as characters. The expression contains parentheses, addition, subtraction, multiplication, and division. | codefeedback |
Write a Bash shell script to find all pairs of prime numbers within a given range of numbers, where the range is defined as the sum of two input numbers. | codefeedback |
Calculate the factorial of the integer "n", where n is a non-negative integer less than or equal to | codefeedback |
Construct a SQL query to generate a report of customers who placed more than 10 orders in the past 6 months and have made at least 3 purchases in the last 14 days. | codefeedback |
Create a VBA macro to find the maximum value of a given range of cells in a Microsoft Excel worksheet. The range of cells can be any size and may contain both numeric and non-numeric values. Additionally, the macro should handle situations where the range of cells contains merged cells or cells with formulas that refer... | codefeedback |
Develop a Python program to calculate the greatest common factor of three positive integers.
The program should prompt the user to enter three positive integers and then calculate the greatest common factor of the three numbers using the Euclidean algorithm. The Euclidean algorithm involves repeatedly dividing the lar... | codefeedback |
Write an efficient algorithm to detect the longest common subsequence of two given strings. The algorithm should have a time complexity of O(n*m), where n and m are the lengths of the input strings, respectively. The algorithm should also handle cases where the input strings contain special characters and spaces. Addit... | codefeedback |
Construct a nested JSON string from the given data, where the nested object represents the person's address and includes the following properties:
- Street: 123 Main St
- City: New York
- State: NY
- Zip code: 12345
Additionally, the nested object should also include the following properties:
- Country: United States
... | codefeedback |
Given a positive integer "n", find the number of trailing zeros in the factorial of "n".
Write a function called "trailing_zeros" that takes in an integer "n" as a parameter and returns the number of trailing zeros in n!.
For example, if n = 20, the factorial of 20 is 2432902008176640000. There are 4 trailing zeros... | codefeedback |
Rewrite the given array of numbers into a binary tree with the following constraints: each node must have at most two children, the left child must be smaller than the parent, and the right child must be larger than the parent. Additionally, the binary tree must be balanced, meaning the difference in height between the... | codefeedback |
Convert the given SQL query into an equivalent MongoDB query. Include an additional requirement to only select users whose age is between 18 and 24 and have a last name starting with the letter "S". However, the last name should be case-insensitive and the age range should be inclusive. | codefeedback |
Write a JavaScript program to implement the bubble sort algorithm for sorting an array of numbers. The program should also include a function to reverse the sorted array. The array should have a length of at least 5 and at most 100. The program should handle duplicate numbers in the array and sort them in ascending ord... | codefeedback |
Write a Python function that implements the quicksort algorithm to sort an array of integers in ascending order. Your function should take in an array as input and return the sorted array. Include the necessary steps involved in partitioning the array and choosing the pivot element.
In your solution, make sure to hand... | codefeedback |
Generate the html markup for a table that contains the given data. The table should also include an additional column that displays the age of each person. The age of each person can be calculated by subtracting their birth year from the current year. The birth year of each person is given in the following format: YYYY... | codefeedback |
Implement a backtracking algorithm to solve a sudoku puzzle with the additional constraints that the solution must be found within a specified time limit of 5 seconds and the algorithm must be able to handle puzzles of size N x N, where N is a positive integer less than or equal to 9. | codefeedback |
You are given a string containing upper and lowercase letters, numbers, and special characters. Write a program to check if it is a palindrome or not. The program should ignore any special characters and only consider the alphanumeric characters for the palindrome check. The program should also handle palindromes with ... | codefeedback |
Make the following code more efficient by implementing it using a single line of code, without using any loops or conditional statements. Additionally, the function should return a new list that maintains the order of the unique elements while removing duplicates. The solution should have a time complexity of O(n), whe... | codefeedback |
Describe the functionality and use cases of a stack and a queue. Compare and contrast the data structures in terms of their operations, properties, and applications. Additionally, provide a detailed implementation of a program in any programming language that solves a specific problem using a stack and a queue. Your pr... | codefeedback |
Create a program to accept a string and display its length. However, the program should also count the number of unique characters in the string and display the count. Additionally, the program should ignore any whitespace characters in the string when counting the length and number of unique characters. In addition, y... | codefeedback |
Create a function that takes an array and a number of elements to append at the end. The function should check if the array is empty before appending the elements. If the array is empty, the function should return a message indicating that the array is empty. If the array is not empty, the function should append the el... | codefeedback |
Modify the following code to output Odd numbers from 1 to 1000 that are prime numbers, with the condition that the prime numbers should be found using the Miller-Rabin primality test algorithm. Additionally, the code should be optimized to have a time complexity of O(log n) for the primality test. | codefeedback |
Code a Python algorithm to reverse a given string while ignoring any non-alphabetic characters and preserving the original capitalization. Additionally, the algorithm should only use a single line of code and should not utilize any built-in string manipulation functions or methods. The string should also be reversed in... | codefeedback |
Using the given list, create a code that will generate a unique list of numbers, while also ensuring that the code has a time complexity of O(n) and a space complexity of O(1). Additionally, the code should only use bitwise operations and cannot use any arithmetic or comparison operators. | codefeedback |
Given a JSON string, write a program to convert it into an equivalent XML string. The JSON string will contain nested objects and arrays.
#Example Input#
{"name":"John","age":30,"city":"New York","hobbies":["reading","painting"],"friends":[{"name":"Sarah","age":28},{"name":"Mike","age":32}]}
#Example Output#
<root>
... | codefeedback |
Develop a Python3 program to extract the words of length 5 or more from a given sentence and print them in descending order of their frequency. Additionally, the program should ignore any punctuation marks and convert all the words to lowercase before processing. | codefeedback |
Write a Bash script that opens an interactive calculator and allows the user to perform basic arithmetic operations (+, -, *, /) on two numbers. The script should also handle error cases, such as dividing by zero or entering invalid input. Additionally, the script should implement a feature where the user can enter mul... | codefeedback |
Modify the following Javascript code to check if a given number is a twin prime or not. A twin prime is a prime number that is either 3 less or 3 more than another prime number. Additionally, the code should also check if the given number is a perfect square. | codefeedback |
Create a function in Python that takes two parameters and calculates the Employee Bonus depending on the hours worked and hourly rate. The function should also check if the hours worked is within the valid range of 0 to 40 and if the hourly_rate is a positive number. If the hours worked is less than 0 or greater than 4... | codefeedback |
Create a Python script that takes in two optional command line parameters:
- A string representing a file name, with a default value of "data.txt".
- An integer representing the maximum number of lines to read from the file, with a default value of 100.
The script should read the specified number of lines from the fil... | codefeedback |
Generate a correct JavaScript code to subtract two numbers using bitwise operators. The input numbers can be positive or negative and can have decimal points. The code should handle all possible edge cases and return the correct result. | codefeedback |
Write a C# program to filter the integers from a given array of mixed data types.
Array = [0, "Apple", 1, "Orange", 2, "Banana", 3, "Mango", 4.5, 5, "Grape"].
Conditions:
1. Entities should be integers.
2. Filtered integers should be greater than or equal to 2 and less than or equal to 4.
Additional instructions:
1. U... | codefeedback |
Develop a jQuery program to toggle the visibility of multiple divs on a webpage. The program should allow the user to toggle the visibility of each div individually by clicking on a corresponding button. Additionally, the program should keep track of the current visibility state of each div, so that when the page is re... | codefeedback |
Create a class called "Car" in Java with the following attributes and methods. The Car class should have additional attributes called "color" (String type) and "model" (String type) which represent the color and model of the car, respectively. The Car class should also have a method called "startEngine" which starts th... | codefeedback |
Find the sum of all the even Fibonacci numbers less than 1 million. | codefeedback |
Update the following HTML code to add a placeholder attribute to the input and restrict the input to only accept alphabetic characters. Additionally, ensure that the input is case-insensitive and display an error message if any non-alphabetic characters are entered. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.