instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Given two strings s1 and s2, find the number of times a substring of s2 with length greater than or equal to 2 appears in s1. Consider the following constraints:
1. Both s1 and s2 can contain uppercase and lowercase letters.
2. The characters in s1 and s2 can be in any order.
3. The characters in s2 can be repeated mu... | codefeedback |
Create a SQL query that returns the number of employees in each city, but only for cities that have more than 10 employees and less than 100 employees. Additionally, include the average age of employees in each city, but only for cities where the average age is above 30. | codefeedback |
Using Python, implement a method to find the longest common subsequence in two strings while considering that the subsequence should contain only alphabetical characters. The two strings should have a minimum length of 10 characters each.
str1 = "AGGTABCDXYZ"
str2 = "GXTXAYBOPQR" | codefeedback |
Write a JavaScript function that takes an array of integers as an argument and returns the sum of the first 10 prime numbers in the array. | codefeedback |
Develop an algorithm to print all the possible n-ary trees with a given number of nodes, where each node can have at most k children. The nodes in the tree can have values from 1 to n. The number of nodes in the tree should be equal to the number of values from 1 to n, without any repetitions.
Example:
n=4, k=3
Possi... | codefeedback |
Please implement a function `validate_IPv4` that takes a string `IP` as input and returns a boolean value indicating whether the given string is a valid IPv4 address.
A valid IPv4 address consists of four decimal numbers separated by periods. Each decimal number must be between 0 and 255, inclusive. Leading zeros are ... | codefeedback |
You need to write an algorithm to find the fourth largest value in a Binary Search Tree, but you are not allowed to use any built-in data structures or methods to traverse or manipulate the tree. Additionally, you are not allowed to use recursion in your algorithm. You must implement your own tree data structure and th... | codefeedback |
Create a script to delete all system logs that are older than 30 days, excluding logs in the "important" folder. Additionally, the script should create a backup of all deleted logs in a separate directory with the current date and time appended to the file name. The script should also generate a report that includes th... | codefeedback |
Suppose a web page contains an unknown number of parameters. Write a function to count the number of parameters present in a given URL. The function should have a time complexity of O(n) and a space complexity of O(1), where n is the length of the URL. Additionally, the function should handle URLs with nested parameter... | codefeedback |
Rewrite the following if-statement into a switch statement with the added requirement that the switch statement must use fall-through behavior. Additionally, the switch statement should handle lowercase and uppercase letters for grades.
if (grade == "A" || grade == "a") {
gradeValue = 4.0;
}
else if (grade == "B" ... | codefeedback |
Write a Java program to find all pairs of integers from an array whose sum equals a given number, but with the additional constraint that each integer can only be used once in a pair. Additionally, the program should optimize for time complexity.
#Explanation#
In the given test, the task is to find pairs of integers f... | codefeedback |
Create a for loop in JavaScript to loop backwards from 100 to 1 and print the value of each iteration to the console. However, you must use a nested if statement within the loop to skip the iteration if the value is divisible by both 2 and 3. Additionally, instead of using console.log to print the values, store the val... | codefeedback |
Determine the function of the Bluetooth signal in the given program.
void setup() {
Serial.begin(9600);
Bluetooth.begin(9600);
}
void loop() {
BluetoothSignal();
}
void BluetoothSignal() {
// Code to send a signal to the Bluetooth module.
// Your task is to modify the BluetoothSignal function to handle mu... | codefeedback |
Modify a given shell script to generate a text-based report of the commands run in the bash shell, excluding any commands that contain a specific keyword specified by the user. Additionally, the report should include the execution time of each command in milliseconds. The script should be able to handle multiple users ... | codefeedback |
Write a function in Python to normalize a given string by following these steps:
1. Remove all white spaces from the string.
2. Convert the string to lower case.
3. Replace all special characters with underscores.
4. Remove duplicate words from the string.
5. Return the normalized string in reverse order.
Example inpu... | codefeedback |
Create a function in Python to add two numbers, which may take any number of arguments. However, the function should also handle invalid inputs such as non-numeric values and return an appropriate error message. Additionally, the function should raise a custom exception if the sum of the numbers exceeds a certain limit... | codefeedback |
Given a function name in JavaScript, write a function that takes in two integer numbers as parameters and returns the remainder of the first parameter divided by the second. The function should also handle cases where either of the parameters is not an integer. Additionally, the function should only use bitwise operato... | codefeedback |
Write the Big O time complexity of the given algorithm.
Algorithm: Finding the value at a given index of a multidimensional unordered array, where the array may contain duplicate values. | codefeedback |
Implement a depth-first search (DFS) algorithm for a tree data structure with the following additional constraints:
- The tree is not guaranteed to be binary, it can have any number of child nodes for each parent node.
- The tree can be arbitrarily large, with up to 10 million nodes.
- Each node in the tree has a uniq... | codefeedback |
Create a SQL query to return the top 10 most popular books, but exclude any books published before the year 2000. Additionally, include a column in the result that shows the total number of copies sold for each book. | codefeedback |
Construct a program in Java to sort an array of String objects in descending order. The program should have a time complexity of O(n log n) and should not use any built-in sorting functions or libraries. Additionally, the program should handle arrays containing up to 1 million elements and should be able to sort the ar... | codefeedback |
Explain the concept of closures in JavaScript and provide an example of how they can be used to create private variables and functions. | codefeedback |
You need to develop a code that takes two strings and returns a boolean if the substrings are anagrams. However, you must now handle cases where the input strings contain spaces, punctuation marks, and special characters. The code should also be case-insensitive. Strings: "Hello, World!" and "world hello!" | codefeedback |
Describe the different thread states in Java programming and provide an example of each state. Additionally, explain the transition between these states and discuss any potential issues or challenges that can arise during these transitions. | codefeedback |
Formulate a SQL query to determine the name of the product with the highest price, considering that the price is stored in a separate table called "product_prices" and the product information is stored in a table called "products". Additionally, the query should only consider products that have a stock quantity greater... | codefeedback |
You need to develop a function which checks if a given string is a palindrome or not. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. The function should meet the following requirements:
1. The function should be case-sensitive, meaning "Redder" should ... | codefeedback |
Develop a function to encode a text string using the Caesar cipher with a variable shift. The shift value should be provided as an argument to the function.
The function should handle special characters, including punctuation marks, and maintain their original positions in the encoded string.
Both uppercase and lower... | codefeedback |
Given two strings, develop a function to calculate the Levenshtein distance between them.
References:
Levenshtein distance is a string metric for measuring the difference between two strings. In simple terms, it calculates the minimum number of single-character edits (insertions, deletions, or substitutions) required ... | codefeedback |
Construct a data mining program to mine public internet data from Twitter datasets. The program should include the following steps:
1. Authenticate with the Twitter API using OAuth 2.0 for secure access to the datasets.
2. Use the Twitter API to search for relevant tweets based on specific criteria, such as keywords, ... | codefeedback |
Create a JavaScript program to make a TCP connection to the server, retrieve the current date and time, and store it in a variable called "dateTime". Additionally, implement error handling to display an error message if the connection fails or if the server does not respond within 5 seconds. | codefeedback |
Create an algorithm that sorts a given list of numbers in descending order and has a time complexity of O(nlogn).
Given an input list of numbers, the algorithm should sort the list in descending order using the Merge Sort algorithm.
1. Divide the input list into two halves, creating left and right sublists.
2. Recurs... | codefeedback |
Create a class to represent an Employee, which includes a name, salary, ID number, a list of projects the employee is currently working on, and a list of skills the employee possesses.
The class should have the following methods:
1. `add_project(project: str)`: Adds a new project to the list of projects the employee i... | codefeedback |
Create a Java program for finding the largest number among an array of n integers. The program should have a time complexity of O(n) and should not use any built-in functions or libraries. Additionally, the program should only iterate through the array once and should not use any additional data structures or variables... | codefeedback |
Given the following nested loop structure, write code to print all elements in the array. The code must be implemented using recursion and must not use any loops or iteration constructs. The array must contain at least 5 sub-arrays and each sub-array must contain at least 3 elements. arr = [[1, 2, 3, 4], [5, 6, 7, 8], ... | codefeedback |
Write a Node.js program which fetches the top 10 trending news from a given website and displays them in reverse chronological order. Additionally, each news item should include the source, publication date, a summary of the news article, and the number of comments on each article. The program should also filter out an... | codefeedback |
List the types of inheritance supported in Java and provide an example of each type. Also, include a piece of erroneous code that demonstrates a common mistake when using one of these types of inheritance.
Erroneous Code:
```java
class Parent {
public void display() {
System.out.println("Parent Class");
... | codefeedback |
Suppose you have a list of numbers and you want to add all the numbers together. Write a loop to do so.
Requirements:
- The time complexity of the solution should be O(n), where n is the number of elements in the list.
- The space complexity of the solution should be O(1), i.e. it should use constant extra space regar... | codefeedback |
Create a React app that loads data from a given REST API endpoint and displays it in a custom-designed grid component. The grid component should have pagination, sorting, and filtering functionality. Additionally, implement a feature that allows the user to update the data on the server-side through the API.
To increa... | codefeedback |
Write a PHP script to connect to a MySQL database and insert a row in the table with values in given fields. Additionally, implement the following checks before inserting the row:
1. Check if the inserted email address is unique and does not already exist in the database.
2. Check if the inserted phone number is in the... | codefeedback |
Translate the sentence "I'm having dinner at 8pm tomorrow" into French, using only the present continuous tense. You must also ensure that the translated sentence uses correct subject-verb agreement and includes the appropriate French prepositions for expressing time and location. | codefeedback |
Create a Python function to sort a list of dictionaries in ascending order of "count", but only include dictionaries that have a key "status" with the value "active". Additionally, ensure that the sorting is stable, meaning that dictionaries with the same "count" value should retain their relative order.
data = [
... | codefeedback |
Design a program in Python which takes a string as input and returns a list of words from the string. The program should remove any punctuation marks from the string before processing. Additionally, the program should also remove any numbers and special characters from the string. | codefeedback |
Write a Python program to insert a given string at a specific position within another given string. The position to insert the string should be randomly generated within a given range. The inserted string should only be inserted if it does not already exist in the original string. Additionally, the program should keep ... | codefeedback |
Convert a string of characters to uppercase in JavaScript, without using any built-in string manipulation functions or methods. The program should also ignore any non-alphabetic characters and only convert alphabetic characters to uppercase. String: hello, world | codefeedback |
Given two lists, write a Python program to print all common elements in them. The program should also remove duplicates from the final list and sort it in ascending order. Additionally, the program should have a time complexity of O(n) and should not use any built-in functions or libraries, except for the following bui... | codefeedback |
Create an algorithm to implement a stack using a single queue, while also ensuring that the time complexity for both push and pop operations is O(1). Additionally, your implementation should handle duplicate elements in the stack, ensuring that the pop operation always removes the most recently pushed duplicate element... | codefeedback |
Write a Python program to replace the last occurrence of a specific element in a list with another given element. The program should find the last index of the specific element and replace it with the given element. If the specific element does not exist in the list, the program should raise a custom exception called "... | codefeedback |
Modify the given code to generate the Fibonacci sequence up to the nth term, without using recursion and without using any additional data structures. Additionally, implement a time complexity of O(n) for the solution. | codefeedback |
Gather data from the web page and write a C# program to extract the page title. The program should also remove any HTML tags and extract the main content of the page. Additionally, the program should handle cases where the page is dynamically generated with JavaScript and retrieve the page title and content accordingly... | codefeedback |
Write a C++ program to rotate an array by 'k' positions in both clockwise and counterclockwise directions. The program should prompt the user to input the array elements and the value of 'k'. It should then validate the input to ensure that 'k' is within the range of valid indices for the array. If the input is valid, ... | codefeedback |
Design a code to check if a given list is ordered in an increasing order. Additionally, count the number of times the order changes within the list.
lst = [1, 2, 3, 5, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,... | codefeedback |
Create a code that removes all duplicate elements in a given array, while also keeping track of the count of each unique element. Additionally, the code should return the unique elements in descending order based on their count. The array should have at least 10,000 elements and all elements should be positive integers... | codefeedback |
Write a code to implement insertion sort on a given list. The list contains positive integers only. The maximum length of the list is 100,000.
#Difficulties Added#
1. Increased the maximum length of the list to 100,000, making the sorting process more time-consuming.
2. Removed the requirement for unique integers in t... | codefeedback |
Modify the following given program to print all prime numbers between 1 and n, where n is a positive integer greater than 1 and less than or equal to 10^9. Additionally, the program should utilize a multi-threaded approach to improve the efficiency of the prime number generation. However, the number of threads used sho... | codefeedback |
Write a code to establish a connection between your server and a remote database. The remote database is hosted on a server with a dynamic IP address and the server is behind a firewall. You need to retrieve the database IP address and the firewall rules dynamically before establishing the connection.
Server host: dyn... | codefeedback |
Write a code to create a 5x5 matrix with all elements as integers, where each row and column must have unique values and the sum of the elements in each row and column must be prime numbers. | codefeedback |
Modify a given code to sort a two-dimensional array (matrix) using bubble sort. The matrix will contain a mix of positive and negative integers. Each row in the matrix may have a different number of elements.
You should also implement an additional feature to sort the matrix in descending order instead of ascending or... | codefeedback |
Write a code to fetch the last 4 commits of a git repository, but only include the commits made by a specific user. The user's username is 'rnyagah' and the repository name is 'GPT-Evaluation'. Additionally, you must implement a feature that calculates and displays the total number of lines added and deleted by the use... | codefeedback |
Write a code to remove all odd numbers from a list using the `remove()` method. The list contains both positive and negative integers.
Example:
Input: [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
Output: [-4, -2, 0, 2, 4]
Your code should remove all odd numbers from the given list and return the modified list. | codefeedback |
Write a Python code using list comprehension to get the power of each odd prime number in a list and store them in a new list. The input list will only contain positive integers.
list_num = [1, 2, 3, 4, 5] | codefeedback |
Below is the code of a shopping list application. Modify it to add a function to calculate the total cost of all items in the list. Additionally, the function should exclude any items that have a price greater than $10 and should round the total cost to the nearest cent. Return the total cost as a string with the dolla... | codefeedback |
Create a subclass 'Manager' of Employee and add the following fields: 'experience', 'teamSize', and 'performanceRatings'. Additionally, implement the following methods:
1. A method to calculate the average performance rating for the manager's team.
2. A method to find the manager with the highest team performance rati... | codefeedback |
Edit the following code to insert a new item at the end of a given Python list. However, you are not allowed to use the append() function or any built-in list methods or functions.
items = [1, 2, 3]
new_item = 4 | codefeedback |
Create a function that takes in a positive integer as input and returns True if the number is a prime number, and False otherwise. Use this function to create a list of the first 10 prime numbers and print out their product. | codefeedback |
Design a singly linked list data structure with the following operations:
1. `void insert(int val)` - Inserts the element `val` at the beginning of the linked list.
2. `void delete(int val)` - Deletes the first occurrence of `val` in the linked list, if it exists.
3. `int search(int val)` - Returns the index of the fi... | codefeedback |
Print the duplicate items in an array of integers in ascending order, where the array size is limited to 1000 and the elements are in the range of -1000 to 1000. If there are no duplicates, output "No duplicates found."
**Example:**
Input: [1, 2, 3, 2, 5, 1]
Output: [1, 2]
**Note:**
- The output should be sorted in ... | codefeedback |
Write a code to input an array and find the maximum and minimum element in it. The array can contain both positive and negative integers. Additionally, you need to find the second minimum and second maximum elements in the array. The size of the array will not exceed 1000 elements.
arr = [1, -2, 3, 4, -5, 6, -7, 8]
C... | codefeedback |
Create a text classifier using a Random Forest algorithm to classify a dataset of movie titles, their corresponding genres, and additional features such as movie directors, actors, release years, and plot summaries. The input dataset is provided as a list of dictionaries, where each dictionary contains the movie title,... | codefeedback |
Write a code in Python to remove all the duplicate elements from a list and print the result. However, you are not allowed to use any built-in Python functions or libraries to achieve this. The code should have a time complexity of O(n), where n is the length of the list.
list: [2, 3, 3, 4, 5, 5]
Note: The list can c... | codefeedback |
Write a code in Java to print out the first 5 prime numbers greater than the given number, while ensuring the output is in ascending order and each number is separated by a comma.
Number: 10 | codefeedback |
Create a function that takes a string, a keyword, and a replacement word, then delete all the occurrences of the keyword in the given string and replace them with the replacement word. The function should be case-sensitive and should also count and return the total number of occurrences of the keyword in the string. Ad... | codefeedback |
Write a code to find the maximum of 5 arguments.
#Additional Instructions#
1. The code should not use any built-in functions or libraries to find the maximum value.
2. The code should handle both positive and negative integers as arguments.
3. The code should handle decimal numbers as arguments.
4. The code should... | codefeedback |
Write an SQL query that returns the average price per category, but exclude any categories that have an average price less than $50. | codefeedback |
Construct a loop that prints the Fibonacci numbers up to the 100th term, one number per line. | codefeedback |
Generate a unique 12-digit hexadecimal code that is a prime number. Additionally, ensure that the code satisfies the following conditions:
1. The code must be a palindrome, i.e., it reads the same forwards and backwards.
2. The code must have exactly 4 distinct prime factors.
3. The sum of the digits of the code must b... | codefeedback |
Implement a search algorithm to search for a node in a binary search tree with a time complexity of O(log n). The algorithm should also keep track of the number of comparisons made during the search process.
In addition to the above requirements, modify the search algorithm to also find the kth smallest element in the... | codefeedback |
Write a code to traverse a matrix in a spiral form while keeping track of the sum of all the elements. Additionally, the code should skip over any negative numbers in the matrix and only consider the positive numbers in the sum calculation. | codefeedback |
What is the Big O notation of the algorithm you wrote in Task 8? Provide a detailed analysis of the time and space complexity of the algorithm, explaining any assumptions or optimizations made.
Additionally, provide a piece of erroneous code that could be easily mistaken as correct, but would introduce a subtle bug or... | codefeedback |
Suggest an efficient algorithm to filter out comments containing profane language in a large text corpus, while also considering context and variations of profanity. Additionally, the solution should be able to handle multilingual comments and provide an accurate profanity detection rate, minimizing false positives and... | codefeedback |
Create a switch statement to convert an RGB value to HEX. The RGB value should be limited to values between 0 and 255, and an error message should be displayed if any of the values are outside this range. The HEX value should be formatted as a 6-digit string preceded by a '#' symbol. Additionally, the program should ha... | codefeedback |
Count the number of occurrences of the letter "a" followed by the letter "b" in a given string. The letter "a" and "b" must be in the same order and adjacent to each other. The input string may contain uppercase and lowercase letters, spaces, punctuation marks, and special characters such as emojis or non-alphanumeric ... | codefeedback |
Create a function that takes an array as a parameter and continuously adds each item to the total sum, but only if the current item is larger than the previous item. The array will only contain positive integers. The function should return the total sum of all the valid items in the array. | codefeedback |
Explain the process of k-fold cross-validation in machine learning, including its advantages and disadvantages compared to other validation techniques. Additionally, provide a piece of erroneous code that attempts to implement k-fold cross-validation, but contains a logical error. Explain what the error is and how it c... | codefeedback |
Suggest a way to generate random passwords using Python with the following requirements:
1. The password must be at least 16 characters long.
2. The password must contain a combination of uppercase and lowercase letters, numbers, and special characters.
3. The password must not contain any repeating characters.
4. The ... | codefeedback |
Transform the following array into an HTML unordered list. Each list item should have a unique identifier based on the index of the array element. The HTML unordered list should be sorted in reverse alphabetical order. Additionally, the HTML unordered list should have nested lists for each vegetable that contain all th... | codefeedback |
Given a string and two words, write a program to find the shortest subsequence containing both words. A subsequence is defined as a sequence of characters that appears in the same order as they do in the original string, but not necessarily consecutively. The program should return the subsequence with the minimum numbe... | codefeedback |
Create a for loop that prints the contents of a list of strings, but with the following additional requirements:
- The time complexity of the solution should be O(n), where n is the length of the list.
- The space complexity of the solution should be O(1), i.e., it should not use any additional memory proportional to t... | codefeedback |
Find the longest substring of four characters that is a palindrome.
string = "banana" | codefeedback |
Write a program that calculates the factorial of a positive integer n, where 1 ≤ n ≤ | codefeedback |
Write a script in Python to make an http request and extract the title of the web page. However, you are not allowed to use any third-party libraries or modules for making the http request or parsing the HTML. You must implement the entire functionality from scratch using only built-in Python modules.
Additionally, yo... | codefeedback |
Find the longest word in a piece of text that is not a palindrome. Make sure to handle cases where there are multiple words with the same length and return the first occurrence of the longest non-palindromic word.
Example:
Input: "The quick brown fox jumps over the lazy dog"
Output: "jump"
Note: The input text will o... | codefeedback |
Edit a given sentence to make its sentence structure correct. The sentence should also not exceed a maximum length of 15 words. sentence = "This wrong sentence structure it needs to be fixed accordingly" | codefeedback |
Perform a bubble sort on the following array of numbers. The array may contain duplicates and the length of the array can be up to 100,000 elements. The input array can be modified in place.
Additionally, implement the bubble sort algorithm in a way that optimizes it for large datasets. This means considering and impl... | codefeedback |
Implement a random number generator in Python that returns a random prime number in the range of 1-10000. | codefeedback |
Create a function to calculate the natural logarithm (log base e) of a given number x in Python. The function should handle negative numbers and return the result with a precision of at least 10 decimal places. The time complexity of the function should be less than O(n), where n is the number of decimal places in the ... | codefeedback |
Write a JavaScript function that takes in a number as input and checks if it is a whole number or has decimals. If the number is a whole number, return true. If the number has decimals, return false.
In your solution, you should not use any built-in JavaScript functions that directly check for whole numbers. Instead, ... | codefeedback |
Create an SQL query to find the First Name and Age of all people with the same Year of Birth, sorted in descending order of their Age. Additionally, only include people whose Age is greater than or equal to 25 and their First Name starts with the letter 'A'. | codefeedback |
Calculate the total product of all odd numbers less than 20 in an array in JavaScript, and return the result rounded down to the nearest integer. The array should contain at least 7 numbers and cannot exceed a length of 15.
#Erroneous Code#
```javascript
function calculateProduct(arr) {
let product = 1;
for (let ... | codefeedback |
Given an array of integers, write an algorithm to find the maximum difference between any two elements in the array. However, the algorithm should have a time complexity of O(n) and should use only a constant amount of extra space.
Provide a piece of erroneous code as a reference to increase misdirection.
nums = [3, ... | codefeedback |
Create a program that assigns a unique ID to each element of an array. The ID should be a combination of a randomly generated alphanumeric string, a timestamp, and a checksum. The alphanumeric string should be at least 20 characters long and should contain a combination of uppercase letters, lowercase letters, numbers,... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.