instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Edit the following HTML code to enable a toggle to show and hide a DIV element when a button is clicked. Additionally, add a feature to change the text of the button when the DIV element is shown or hidden.
<div>
<button>Toggle</button>
<p>This is a text paragraph.</p>
</div>
Requirements:
1. The toggle should wo... | codefeedback |
Write a program that generates all possible permutations of a given string. | codefeedback |
You are given a string "hello". Write a function to print out all the possible subsets of that string, but with the following additional constraints:
- The subsets should only include contiguous characters from the original string.
- The subsets should not contain any duplicate characters.
- The subsets should be print... | codefeedback |
Using a Node.js code, create an HTTP request to get the response status code of a given URL and parse the response body to extract all the hyperlinks present in the HTML content. The program should then make subsequent HTTP requests to each of these extracted hyperlinks and calculate the average response time of all th... | codefeedback |
Given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.
Additional Requirements:
1. The time complexity of your solution should be O(max(m, n)), where m and... | codefeedback |
Analyze the following code and determine if there any potential errors.
def foo(X, Y):
for i in range(1, X): # Step 1
for j in range(1, Y): # Step 2
print(i) # Step 3
return
In this code, the function foo takes two parameters, X and Y. It uses two nested... | codefeedback |
What is the purpose of Java virtual machine and how does it interact with the operating system to manage memory allocation and garbage collection? | codefeedback |
Create an algorithm to calculate the nth Fibonacci number, where n can be up to 10^6.
Note: The Fibonacci sequence is defined as follows:
F(0) = 0
F(1) = 1
F(n) = F(n-1) + F(n-2) for n > 1 | codefeedback |
Develop a method to achieve the linear interpolation between two given points using a custom equation instead of the standard formula for linear interpolation. | codefeedback |
Alter the following code to create a function called "find_largest" to find the largest prime number in a given list of integers. The function should return -1 if there are no prime numbers in the list.
[9, 11, 7, 16, 20] | codefeedback |
Create a TensorFlow program to implement a multi-layer neural network that uses the Adam optimizer and applies L2 regularization to the weight matrices. | codefeedback |
Create a data structure to store the 10 highest scores of a given game. Implement a function to add a new score to the data structure while maintaining the order of the scores in descending order. Also, implement a function to retrieve the highest score from the data structure. | codefeedback |
Generate code for printing a given 2D matrix in spiral order. The matrix may contain negative numbers as well.
matrix = [[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]]
Note: The code should handle matrices of any size. | codefeedback |
Create a function to print the contents of a binary tree in pre-order format. Additionally, handle cases where the binary tree is empty or contains invalid values. | codefeedback |
Suggest a way to serialize a binary tree in Python, but ensure that the serialization is in a specific order based on the values of the nodes. | codefeedback |
Compute the sum of the integers in the given array.
Integers in the array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Note: The array may contain up to 10^6 integers. | codefeedback |
Write an algorithm to store the data in a 2D array. The input will be a string representation of the array in the following format: "[[1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16]]". The algorithm should parse the string and store the values in a 2D array.
Erroneous code reference:
The algorithm should also check ... | codefeedback |
Alter the code to return the last element of a singly linked list that is sorted in ascending order and contains only positive integers. | codefeedback |
Create a doubly linked list to store the values ```[10, 20, 30]```. | codefeedback |
Write a MySQL query to select the first 3 rows of the student table, ordered by the average of their exam scores in descending order. | codefeedback |
Create an object method to calculate the area of a triangle in Python. However, the input parameters for the method should not be the length of the sides of the triangle, but instead the coordinates of its vertices. | codefeedback |
Write an SQL query to select the gender, age, and count of people from the people table for people aged 20-30, but exclude anyone whose name starts with the letter 'A'. | codefeedback |
Create a function in Java to print out all substrings of an input string, but exclude substrings that are palindromes. | codefeedback |
Create a text classification model using Scikit-learn to classify a message with one of the following sentiments: "positive", "negative", or "neutral". Additionally, implement a feature extraction technique such as TF-IDF or word embeddings to improve the model's accuracy. | codefeedback |
Implement a queue data structure in Java using a linked list. The queue should support the following operations:
- enqueue(element): Insert an element to the back of the queue.
- dequeue(): Remove and return the element from the front of the queue.
- peek(): Return the element at the front of the queue without removing... | codefeedback |
Create a function that returns a list of all the factors of a given number, excluding 1 and the number itself. | codefeedback |
Compare two Python lists having integers and write a function to output the differences. However, the function should only consider the elements in list_a that are not present in list_b, and vice versa. The order of the elements in the output should match the order of the elements in list_a.
list_a = [1, 2, 3, 4]
lis... | codefeedback |
Write a Python code to convert a binary tree to its mirror tree without using recursion. The code should have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Design a data structure that can efficiently store the capitals of different countries and their respective populations, while also allowing for quick retrieval of the countries with the highest population. | codefeedback |
Write a code to convert a given string of English characters to corresponding Morse code, while considering the following constraints: The string may contain numbers and special characters. Each Morse code representation should be separated by a space. The program should also handle upper and lower case characters, tre... | codefeedback |
Write a SQL query to select the latest registration record for each user, considering only the records that were registered after a certain date. | codefeedback |
Create a robust Helper Function in PHP that returns an array containing the N most frequent words in a string. The input string may contain punctuation marks and special characters, and the function should handle them properly. Also, the function should consider words that are in different cases (e.g., "The" and "the")... | codefeedback |
Write an R script to find the correlation between two columns in a given Data Frame, but exclude any rows where either of the columns contains missing values. | codefeedback |
Design a NodeJS script to call a remote API and convert the response to a csv object. Additionally, the script should validate and sanitize the API response data, handle any potential errors or exceptions during the API call, and implement error logging for debugging purposes. | codefeedback |
Find the average of the absolute values of five numbers, excluding any negative numbers.
-11, 15, -20, 7, -19 | codefeedback |
Edit the following React component to make the text input to accept only number values. Additionally, implement a validation that checks if the entered number is within a specified range.
<input type="text" value={value} onChange={handleChange} />
Requirements:
1. The text input should only accept numerical values. A... | codefeedback |
Write a Python program that reads a specific compression format such as .zip, extracts its contents, and saves them to a specified directory. The program should prompt the user to enter the path of the .zip file and the destination directory. It should then validate the input, check if the .zip file exists, and if the ... | codefeedback |
Create a function that takes in two integers, `start` and `end`, and returns an array of prime numbers between `start` and `end`. Print out the array of prime numbers. | codefeedback |
Construct a function to convert a string of any length to a capitalized version. The function should handle multiple words in the string and capitalize the first letter of each word. | codefeedback |
Create an Angular service to authenticate a user using an API endpoint. The service should also handle refreshing the user's access token automatically when it expires, without requiring the user to re-enter their credentials. | codefeedback |
Parse the following HTML string and return the list of id's. The solution should handle nested HTML elements and should not use any external libraries or frameworks. | codefeedback |
Write a SQL query that reverses the order of entries in table 'students' by using a temporary table. | codefeedback |
Construct a regex expression that matches a valid US zip code and also ensures that the zip code is for a specific state. | codefeedback |
What type of sorting algorithm does the following Python code implement? The algorithm must have a time complexity of O(nlogn) and must be an in-place sorting algorithm. | codefeedback |
Construct a function that removes any non-alphanumeric characters from a string and returns the modified string.
However, in this rewritten test, you should also consider removing any special characters that might be present within alphanumeric characters. For example, if the input string is "h-e_l9lo", the function ... | codefeedback |
Identify the data structure used in the given implementation. Additionally, implement a function that performs a specific operation on the data structure. The function should take an extra parameter and modify the data structure based on its value. | codefeedback |
Modify the function to include a message about the length of the string. The string should not contain any numbers. message = "The length of the string is:". The function should also check if the string is in uppercase and return True if it is. | codefeedback |
Find the runtime complexity of this Python program.
def EvenOrOdd(items):
if len(items) == 0:
return 0
even_count = 0
for item in items:
if item % 2 == 0:
even_count += 1
return even_count
#Proposed Solution#
The given program has a runtime complexity of O(n), where n is t... | codefeedback |
Compute the sum of two matrices of size m x n. A = [[1, 2], [4, 5]] and B = [[3, 6], [7, 8]]. Each matrix can only contain positive integers. The sum matrix should satisfy the constraint that the sum of all its elements is greater than 10. | codefeedback |
Write a code snippet to display the Fibonacci sequence up to the 50th term, where each term is a prime number. | codefeedback |
Debug this Java code and explain what was wrong. Additionally, ensure that the function can handle negative numbers and float values as inputs, and modify it to return the result as a double type. | codefeedback |
Create a doubly linked list class with the following methods:
1. `insert(data)`: Insert a new node with the given data at the beginning of the list.
2. `append(data)`: Insert a new node with the given data at the end of the list.
3. `delete(data)`: Delete the first occurrence of a node with the given data from the lis... | codefeedback |
Modify the function to return the least common multiple of three positive integers instead. | codefeedback |
What is the value of "arr" after executing this code? Find a solution with a time complexity of O(n), where n is the length of the input array.
arr = [1, 2, 3]
for i in range(len(arr)):
arr[i] = arr[i] + 1
arr.append(4) | codefeedback |
Create a function that takes two integers, A and B, and returns the largest common divisor between A and B. Your solution should not use any built-in functions or libraries for calculating the greatest common divisor. | codefeedback |
Write a code that takes a list of numbers, and outputs the 10th largest value. However, the code must not use any built-in sorting functions or methods.
mylist = [2, 4, 54, 31, 34, 77, 29, 11, 44, 78, 65, 23] | codefeedback |
What is the best way to check if a given input is a prime number within a given range? | codefeedback |
Sort the strings in descending order.
items = ["Red", "Blue", "Yellow", "Green"] | codefeedback |
Given a string, write a regular expression to extract the last three words that start with a capital letter of the string.
text = "My name is Bill Gates. He is the founder of Microsoft and a billionaire." | codefeedback |
Create a neural network class in Python using NumPy with the following requirements:
1. The neural network should have at least two hidden layers.
2. Implement a method to initialize the weights and biases of the neural network randomly.
3. Implement a method to forward propagate inputs through the neural network.
4. ... | codefeedback |
Prepare a code to select all rows that have more than one occurrence of the same value in a given column. The code should also remove any duplicate rows from the resulting selection. The selected rows should be ordered in descending order based on the number of occurrences of the same value. If multiple rows have the s... | codefeedback |
Create a function to calculate the total cost of the items in a cart, where the cart can contain multiple instances of the same item.
items = [{"item":"apple", "cost":3.00, "quantity":2}, {"item":"orange", "cost":2.50, "quantity":3}]
In addition to calculating the total cost, the function should also return the item w... | codefeedback |
Increase the difficulty by adding a requirement to implement a specific method in the "MyClass" class and use it in the main method.
Add a class "MyClass" to the given Java code with the following specifications:
1. Include a private instance variable "name" of type String.
2. Implement a constructor that takes a Str... | codefeedback |
Describe the purpose of an iterator class in Java and provide an example of how it can be used to iterate over a collection of objects. Additionally, explain the concept of "fail-fast" in relation to iterators and how it can be achieved in Java. | codefeedback |
Write an algorithm to find the missing number in an array of n consecutive integers in Python. The array may contain duplicate numbers.
arr = [1, 2, 2, 3, 3, 5, 6, 7, 7, 8]
Note: The array may have duplicates and the missing number can also be a duplicate. | codefeedback |
Rewrite the following sentence so that it has a different meaning and includes more logical steps: We should carefully analyze and evaluate multiple approaches in order to effectively solve this complex problem and achieve optimal results. | codefeedback |
Create a method with the following signature: int calculateSum(int x, int y) that calculates the sum of x and y. The method should only use bitwise operators (e.g. &, |, ^, ~, <<, >>) and should not use any arithmetic operators (+, -, *, /). | codefeedback |
Read the following code and suggest an optimization that calculates the sum of the even numbers in the array. The array contains only positive integers and has a length of at least 10. The optimized solution should use a single loop to iterate through the array. | codefeedback |
You need to generate a Javascript program that prints "Hello World" using a recursive function. | codefeedback |
Edit the given code snippet and make it run in O(N) time complexity, while also ensuring that the algorithm uses constant space complexity. Additionally, the solution should be implemented using a recursive approach. | codefeedback |
Implement a modified version of the quicksort algorithm to sort a large, unsorted integer array. The modified quicksort algorithm should use the median of three pivot selection strategy to improve its efficiency. Additionally, the algorithm should be implemented in a way that avoids recursive calls and instead uses an ... | codefeedback |
Design a Java program to find the longest increasing sub-sequence of an array, where the sub-sequence must have a minimum length of 3 and the array can contain duplicate elements. | codefeedback |
Create an array that contains the numbers 1 through 10, but do not use any loops or built-in functions to generate the array. | codefeedback |
Write a function to calculate the median of an array of integers. The median is the middle value of a sorted array. If the array has an odd number of elements, the median is the middle element. If the array has an even number of elements, the median is the average of the two middle elements.
You can assume that the ar... | codefeedback |
Produce an HTML webpage that shows a table of 20 randomly generated colors and their corresponding hexcodes. Each color should be unique and not repeated in the table. | codefeedback |
How to convert a binary string to an integer number without using any built-in functions or libraries?
binaryNum = "1101" | codefeedback |
Create a class in Java for a student and define variables for name, date of birth, grade, and a list of subjects the student is enrolled in. Each subject should have a name and a grade.
Additionally, implement the following methods in the student class:
1. A method to add a subject to the list of enrolled subjects. T... | codefeedback |
Build a Keras model to predict whether a patient has cancer, using only a small subset of features from a large dataset of patient medical records. The model should achieve an accuracy of at least 90% on a held-out test set. Additionally, the model should be able to handle imbalanced classes, as the dataset has a highe... | codefeedback |
Design a pipeline in Scikit-learn to preprocess a given dataset. The pipeline should include the following steps:
1. Remove any duplicate rows from the dataset.
2. Convert all categorical variables in the dataset to numerical variables using one-hot encoding.
3. Impute missing values in the numerical variables using th... | codefeedback |
Write an R script to generate a word cloud of a given text, but exclude common words such as articles, prepositions, and conjunctions from the word cloud. The word cloud should only include nouns, verbs, and adjectives. The generated word cloud should also display the frequency of each word.
text = "This is a sample ... | codefeedback |
Create an Excel spreadsheet that compares the performance of an employee over two different months. The spreadsheet should include the following additional constraints and requirements:
- The employee's performance should be calculated based on their sales per hour ratio.
- In addition to the sales and hours worked dat... | codefeedback |
Write a multithreaded program in Java that simulates a bank with multiple ATMs. Each ATM is represented by a separate thread and can perform transactions such as withdrawal, deposit, and balance inquiry concurrently with other ATMs. The program should ensure thread safety and handle synchronization issues using appropr... | codefeedback |
Describe the time complexity and space complexity when sorting a list using bubble sort algorithm and provide a step-by-step explanation of the sorting process. | codefeedback |
Extract the domain names from the given list of URLs while ignoring subdomains. Each domain name should consist of at least two parts separated by a dot. The output should be sorted in alphabetical order. The input list of URLs will not exceed 1000.
url_list = [ "www.abcd.com", "www.something.co.in", "www.example.ng" ... | codefeedback |
Generate a correct Python code for a data structure which supports the following operations -
insert(key, value)
get(key)
delete(key)
Also, make sure to implement the following additional functionality:
1. The data structure should have a method to check if a key exists in the data structure.
2. The delete(key) opera... | codefeedback |
Write a script in Java for printing the first n Fibonacci numbers. Additionally, implement a recursive solution for finding the nth Fibonacci number. | codefeedback |
Given a list of integers and a target sum, write a function that returns a pair of said integers that add up to the target sum. The pair of integers must also be unique, meaning that if there are multiple pairs that satisfy the condition, the function should return the pair with the smallest absolute difference between... | codefeedback |
Generate a code in Java for sorting an array using Mergesort, but with the additional constraint that the merge operation must be implemented iteratively instead of recursively. | codefeedback |
Write a Python function to analyze the performance of different sorting algorithms. The function should take in a list of integers and return a dictionary containing the number of comparisons and swaps made by each sorting algorithm. The list will have a minimum length of 10 and a maximum length of 1000. The integers i... | codefeedback |
Create an HTML table that displays the data in a given JSON object. The JSON object will contain multiple rows of data, each consisting of a location, age, and name. The table should have the following features:
1. The table should have a header row that displays the column names: "location", "age", and "name".
2. Eac... | codefeedback |
Sort a list of integers using quicksort algorithm recursively.
list = [4,2,1,5,3]
Steps:
1. Choose a pivot element from the list. In this case, let's choose the first element, 4, as the pivot.
2. Partition the list into two sublists: one with elements smaller than the pivot and one with elements greater than the pivo... | codefeedback |
Construct a SQL query to list the unique countries from table countries, but exclude any countries that have a population greater than 100 million. | codefeedback |
Create a class in Python that can be used to store the details of a student. The class should have the following attributes: name, age, grade level, and a list of subjects.
The class should also have the following methods:
1. `add_subject(subject)`: This method should take a subject as input and add it to the list of... | codefeedback |
Construct a SQL query to count the number of distinct cities that have a population greater than 1 million from table cities. | codefeedback |
Generate a Java program to get the maximum number from a given array. The program should also return the index of the maximum number. Additionally, the program should handle arrays of any size and should have a time complexity of O(n) or better. | codefeedback |
Find the maximum value in the array [1, 2, 2, 4, 5, 5]. | codefeedback |
Change the following code to use the ternary operator.
def compare_num(a, b):
return -1 if a < b else (0 if a == b else 1) | codefeedback |
Compute the factorial of the positive integer 7 using recursion, ensuring that the input number is less than or equal to 10. | codefeedback |
How would you merge two sorted linked lists into one, using recursion? | codefeedback |
Given a string, write a Java program to verify if it is a valid email address and also check if the email address belongs to a specific domain. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.